I have the following case:
var testSchema = new mongoose.Schema(
{
name: { type: String, required: true },
title: { type: String },
subArray: [ testSchema ]
}
);
var testModel = mongoose.model('Test', testSchema);
When I do the following:
testModel.findOne({ name: 'test-name' }).exec(function(err, doc) {
doc.populate({ path: 'subArray', model: 'testModel' }, function(err, d) { });
});
doc is found but after the populate function executes the subArray is not populated.
It shows that there is one element in subArray (correctly) but the actual element itself is undefined.
How do I populate subArray?
What am i doing wrong?
mongoose version I'm using is 3.8.22.