Removing specific items from array with MongoDB

If you can identify the comment item by matching userid, name or comment — then you can remove that comment using update() command with $pull modifier along with the appropriate condition.

If you cannot do as above, include an unique id in the comments (like UUID).

To delete the comment, do the following:

db.coll.update({<cond to identify document}, {$pull: {'comments': {'name': <name>}}} )

If you use the id, which is preferred:

db.coll.update({<cond to identify document}, {$pull: {'comments': {'id': <id>}}} )

Leave a Comment