arrayFilters in mongodb

You need to use new: true to get the updated value and cast id to mongoose objectId to make it work

Post.findOneAndUpdate(
   { 'posts.replies._id': _id }, 
   { $set: { 'posts.$[post].replies.$[reply].text': "something1" } },
   { arrayFilters: [{ 'post._id': postId }, { 'reply._id': _id }], new: true }
)

Leave a Comment