I'm stuck trying to figure out if this is possible.
Using the mongoose blog example to demonstrate, however, my actual use case is a bit more complicated:
var Comments = new Schema({ title : String , body : String , date : Date }); var BlogPost = new Schema({ author : ObjectId , title : String , body : String , date : Date , comments : [Comments] }); var BlogPost = mongoose.model('BlogPost'); var post = new BlogPost();
I need to create a new comment and return a new comment to the client. Having comments as an embedded document is really convenient for me and works well. However, I do not want to return every comment to the client every time I add a new one.
post.comments.push({ title: 'My comment' });
Since I use mongoose, if I could, how to get the id new comment, which will help, and also allow me to add other functions, such as editing a comment or deleting a comment.
The only way to do this is to have comments as your own collection?
source share