DocumentDB LogoDocumentDB
HomeGitHubDiscordDocsPackagesBlogs
Back to DocumentationMQL Documentation
Commands
Aggregation
Query And Write
Operators
Accumulators
Aggregation
Arithmetic Expression
Array Expression
Array Query
Array Update
$
$[]
$[identifier]
$addToSet
$each
$pop
$position
$pull
$pullAll
$push
Bitwise
Bitwise Query
Bitwise Update
Comparison Query
Conditional Expression
Data Size
Date Expression
Element Query
Evaluation Query
Field Update
Geospatial
Literal Expression
Logical Query
Miscellaneous
Miscellaneous Query
Object Expression
Projection
Set Expression
Timestamp Expression
Variable Expression
Window Operators
Reference/Operators/Array Update

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.

Copyright © DocumentDB a Series of LF Projects, LLC. For web site terms of use, trademark policy and other project policies please see https://lfprojects.org.