Skip to content

Instantly share code, notes, and snippets.

@bvanasse
Last active August 29, 2015 14:05
Show Gist options
  • Save bvanasse/3d9ea919be3976070cd2 to your computer and use it in GitHub Desktop.
Save bvanasse/3d9ea919be3976070cd2 to your computer and use it in GitHub Desktop.
if the database is empty on server start, create some sample data
// https://github.com/meteor/meteor/blob/devel/examples/todos/server/bootstrap.js
// if the database is empty on server start, create some sample data.
Meteor.startup(function () {
if (Lists.find().count() === 0) {
var data = [
{name: "Name",
contents: [
["A", "B", "C"],
["One Language", "Simplicity", "Fun"]
]
}
];
var timestamp = (new Date()).getTime();
for (var i = 0; i < data.length; i++) {
var list_id = Lists.insert({name: data[i].name});
for (var j = 0; j < data[i].contents.length; j++) {
var info = data[i].contents[j];
Todos.insert({list_id: list_id,
text: info[0],
timestamp: timestamp,
tags: info.slice(1)});
timestamp += 1; // ensure unique timestamp.
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment