Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User.findOneAndUpdate(
- {
- 'posts._id': req.params.id
- },
- {
- $push: {
- 'posts.$.comments': {
- from: {
- _id: req.user._id,
- username: req.user.username,
- },
- body: req.body.commentBody
- }
- }
- },
- err => {
- if (err) console.log(err)
- // Do something with ObjectId
- }
- );
- var mypost = doc.posts.find(function(post){
- return post._id.toString()==req.params.id
- });
- console.log(mypost.comments[mypost.comments.length]._id)
Add Comment
Please, Sign In to add comment