Database Manual / Reference / Query Language / Update

Array Update Operators数组更新运算符

Note

For details on a specific command, including syntax and examples, click on the link to the command's 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条件匹配的所有元素。
$addToSetAdds elements to an array only if they do not already exist in the set.仅当元素在集合中不存在时,才向数组添加元素。
$popRemoves the first or last item of an array.删除数组的第一项或最后一项。
$pullRemoves all array elements that match a specified query.删除与指定查询匹配的所有数组元素。
$pushAdds an item to an array.将项添加到数组中。
$pullAllRemoves all matching values from an array.从数组中删除所有匹配的值。

Update Operator Modifiers更新运算符修改器

Name名称Description描述
$eachModifies the $push and $addToSet operators to append multiple items for array updates.修改$push$addToSet运算符,以附加多个项进行数组更新。
$positionModifies the $push operator to specify the position in the array to add elements.修改$push运算符以指定在数组中添加元素的位置。
$sliceModifies the $push operator to limit the size of updated arrays.修改$push运算符以限制更新数组的大小。
$sortModifies the $push operator to reorder documents stored in an array.修改$push运算符以重新排序存储在数组中的文档。