Google Groups

Re: Cannot call method path on undefined when populating


Arlo Feb 1, 2012 3:33 AM
Posted in group: Mongoose Node.JS ODM
I've run into this crash tonight as well. I'm using the current version of Mongoose.

My structure seems to be identical (this is trimmed):

The Models:

Share = new Schema({
data: String,
comments: [Comment],
user_id: { type: Schema.ObjectId, ref: 'User' }
});

Comment = new Schema({
data: String,
user_id: { type: Schema.ObjectId, ref: 'User' }
});

Inside Node/Express:

Share.findById( req.params.id ).populate('comments.user_id').run( function(err, share) {
res.send(share.comments);
});

Crash:

TypeError: Cannot call method 'path' of undefined
    at /home/ubuntu/www/node_modules/mongoose/lib/model.js:234:44
    at /home/ubuntu/www/node_modules/mongoose/lib/model.js:240:14
    at Array.forEach (native)