Was checking out Mongoose and the relatively new populate method. Seems to work perfect when populating from the child to the parent like so:
var Comment = new Schema({
Message: { type: String }
User: { type: ObjectId, ref: 'User' }
});
var User = new Schema({
Username: { type: String }
Comments: [{ type: ObjectId, ref: 'Comment' }]
});
The following works as expected.
Comment.find({}).populate({ path: 'User' }).exec(function (err, comments) {
if(err) handle(callback);
// no error do something with comments/user.
// this works fine and populates the user perfectly for each comment.
});
User.findOne({ Username: "some username"}).populate('Comments').exec(function (err, user) {
if(err) handle(callback);
// this throws no errors however the Comments array is null.
// if I call this without populate I can see the ref ObjectIds in the array.
});
The fact that the ObjectIds are visible without calling populate on the User model/schema and the fact that I can populate just fine from the child side ref makes it appear that the configuration is correct yet no joy.
The above schemas were shorted so as not to post a mile long list of code ( I hate that!!!). Hoping I'm missing something simple.