MongoDB Query Language (MQL) Array Update Operators
Array update operators are used to modify array fields within documents during update operations. These operators enable you to add, remove, or manipulate elements in arrays, providing fine-grained control over array field updates including appending values, removing specific elements, and controlling array size.
$
The $ positional operator identifies an element in an array to update without explicitly specifying the position of the element in the array.
$addToSet
The addToSet operator adds elements to an array if they don't already exist, while ensuring uniqueness of elements within the set.
$each
The $each operator is used within an `$addToSet` or `$push` operation to add multiple elements to an array field in a single update operation.
$pop
Removes the first or last element of an array.
$[]
The $[] operator is used to update all elements in an array that match the query condition.
$[identifier]
The $[] operator is used to update all elements using a specific identifier in an array that match the query condition.
$position
The $position is used to specify the position in the array where a new element should be inserted.
$pull
Removes all instances of a value from an array.
$pullAll
The $pullAll operator is used to remove all instances of the specified values from an array.
$push
The $push operator adds a specified value to an array within a document.