I have a MongooseJS schema where a parent document references a set of sub-documents:
var parentSchema = mongoose.Schema({
items : [{ type: mongoose.Schema.Types.ObjectId, ref: 'Item', required: true }],
...
});
For testing I'd like to populate the item array on a parent document with some dummy values, without saving them to the MongoDB:
var itemModel = mongoose.model('Item', itemSchema);
var item = new itemModel();
item.Blah = "test data";
However when I try to push this object into the array, only the _id is stored:
parent.items.push(item);
console.log("...parent.items[0]: " + parent.items[0]);
console.log("...parent.items[0].Blah: " + parent.items[0].Blah);
outputs:
...parent.items[0]: 52f2bb7fb03dc60000000005
...parent.items[0].Blah: undefined
Can I do the equivalent of `.populate('items') somehow? (ie: the way you would populate the array when reading the document out of MongoDB)