Docs Home → MongoDB Manual
Array Update Operators数组更新运算符
Note 注意
For details on specific operator, including syntax and examples, click on the specific operator to go to its reference page.有关特定运算符的详细信息,包括语法和示例,请单击特定运算符以转到其参考页。
Update Operators更新运算符
Name名称 Description描述
$
Acts as a placeholder to update the first element that matches the query condition.用作占位符以更新与查询条件匹配的第一个元素。
$[]
Acts as a placeholder to update all elements in an array for the documents that match the query condition.充当占位符,更新数组中与查询条件匹配的文档的所有元素。
$[<identifier>]
Acts as a placeholder to update all elements that match the arrayFilters
condition for the documents that match the query condition.用作占位符,以更新与查询条件匹配的文档中与arrayFilters
条件匹配的所有元素。
$addToSet
Adds elements to an array only if they do not already exist in the set.仅当元素不存在于集合中时,才将元素添加到数组中。
$pop
Removes the first or last item of an array.移除数组的第一项或最后一项。
$pull
Removes all array elements that match a specified query.删除与指定查询匹配的所有数组元素。
$push
Adds an item to an array.将项添加到数组。
$pullAll
Removes all matching values from an array.从数组中删除所有匹配值。
Update Operator Modifiers更新运算符修饰符
Name名称 Description描述
$each
Modifies the $push
and $addToSet
operators to append multiple items for array updates.修改$push
和$addToSet
运算符,以便为数组更新附加多个项。
$position
Modifies the $push
operator to specify the position in the array to add elements.修改$push
运算符以指定数组中要添加元素的位置。
$slice
Modifies the $push
operator to limit the size of updated arrays.修改$push
运算符以限制更新数组的大小。
$sort
Modifies the $push
operator to reorder documents stored in an array.修改$push
运算符以重新排序存储在数组中的文档。