Skip to content

Instantly share code, notes, and snippets.

@naholyr
Last active December 28, 2015 21:08
Show Gist options
  • Save naholyr/7562037 to your computer and use it in GitHub Desktop.
Save naholyr/7562037 to your computer and use it in GitHub Desktop.
Mongoose fixtures proposal
{
// 1 document in this collection
"Collection": [
{"fieldName": "value", "dbRefField": {"$ref": "OtherCollection", "$idx": 0}}
// dbRefField == OtherCollection[0] once made available
],
// 2 documents in this collection
"OtherCollection": [
{"otherField": "value1"},
{"otherField": "value2"}
]
}
async.auto({
"Collection:0": ['OtherCollection:0', function (cb, o) { (new Collection({fieldName: "value", dbRefField: o['OtherCollection:0']})).save(cb) }],
"OtherCollection:0": function (cb) { (new OtherCollection({otherField: "value1"})).save(cb) },
"OtherCollection:1": function (cb) { (new OtherCollection({otherField: "value2"})).save(cb) }
}, function (err, res) {
/* … */
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment