$pullAll
The $pullAll operator in Amazon DocumentDB is used to remove all instances of the specified values from an array field. This is particularly useful when you need to remove multiple elements from an array in a single operation.
Parameters
-
field: The name of the array field from which to remove the elements. -
value: An array of values to remove from the array field.
Example (MongoDB Shell)
The following example demonstrates how to use the $pullAll operator to remove multiple elements from an array field.
Create sample documents
db.restaurants.insert([ { "name": "Taj Mahal", "cuisine": "Indian", "features": ["Private Dining", "Live Music"] }, { "name": "Golden Palace", "cuisine": "Chinese", "features": ["Private Dining", "Takeout"] }, { "name": "Olive Garden", "cuisine": "Italian", "features": ["Private Dining", "Outdoor Seating"] } ])
Query example
db.restaurants.update( { "name": "Taj Mahal" }, { $pullAll: { "features": ["Private Dining", "Live Music"] } } )
Output
{
"name": "Taj Mahal",
"cuisine": "Indian",
"features": []
}
Code examples
To view a code example for using the $pullAll command, choose the tab for the language that you want to use: