Delete single array object in mongodb uing $unset

Viewed 29
1 Answers

You can use $pull operator

db.collection.update({
    { _id : id },
    { $pull: { "favorite book": "Ender's Game" } }
});

If you want to remove two or more elements from the array "list", you can do that with $pull operator, as well:

db.collection.update({
    { _id : id },
    { $pull: { "favorite book" : { $in : [ "Foundation Trilogy", "Ender's Game"] } } }
});

Please check How do I remove a string from an array in a mongodb document?

Related