I have built-in comments in the message model. I use mongoosejs. After clicking on the new comment in the post, I want to access the ID of the newly added inline comment. Not sure how to get this.
This is what the code looks like.
var post = Post.findById(postId,function(err,post){ if(err){console.log(err);self.res.send(500,err)} post.comments.push(comment); post.save(function(err,story){ if(err){console.log(err);self.res.send(500,err)} self.res.send(comment); }) });
In the above code, the comment identifier is not returned. Note that there is a _id field that is created in db.
The circuit looks like
var CommentSchema = new Schema({ ... }) var PostSchema = new Schema({ ... comments:[CommentSchema], ... });
source share