Reputation: 20438
I'm trying to do something similar to the following
http://mongoosejs.com/docs/embedded-documents.html
However instead of new BlogPost I'm trying to retrieve then add as follows
function addComment(id, comment, callback) {
Post.findOne(id, function(err, post) {
post.comments.push(comment);
});
}
I'm getting
TypeError: Cannot call method 'call' of undefined
What am I doing wrong? I left out the saving code for simplification it is crashing even without trying to save.
Upvotes: 0
Views: 102
Reputation: 311835
Assuming that the id
parameter is an ObjectId or string (and not a query object), you should be calling findById
instead of findOne
.
Upvotes: 1