On this page本页内容
The following modifiers are available for use in update operations, for example, in 以下修饰符可用于更新操作,例如,在db.collection.updateMany()
and db.collection.findAndModify()
.db.collection.updateMany()
和db.collection.findAndModify()
中。
Specify the operator expression in a document of the form:在以下格式的文档中指定运算符表达式:
{ <operator1>: { <field1>: <value1>, ... }, <operator2>: { <field2>: <value2>, ... }, ... }
For details on specific operator, including syntax and examples, click on the specific operator to go to its reference page.有关特定运算符的详细信息,包括语法和示例,请单击特定运算符以转到其参考页。
Starting in MongoDB 5.0, update operators process document fields with string-based names in lexicographic order. 从MongoDB 5.0开始,更新运算符以字典顺序使用基于字符串的名称处理文档字段。Fields with numeric names are processed in numeric order.具有数字名称的字段按数字顺序处理。
In MongoDB 4.4 and earlier, update operators process all document fields in lexicographic order.在MongoDB 4.4及更早版本中,更新运算符按字典顺序处理所有文档字段。
Consider this example 考虑这个示例$set
command:$set
命令:
{ $set: { "a.2": <new value>, "a.10": <new value>, } }
In MongoDB 5.0 and later, 在MongoDB 5.0及更高版本中,"a.2"
is processed before "a.10"
because 2
comes before 10
in numeric order."a.2"
在"a.10"
之前处理,因为2
以数字顺序出现在10
之前。
In MongoDB 4.4 and earlier, 在MongoDB4.4及更早版本中,"a.10"
is processed before "a.2"
because 10
comes before 2
in lexicographic order."a.10"
在"a.2"
之前处理,因为按照字典顺序,10
在2
之前。
$currentDate | |
$inc | |
$min | |
$max | |
$mul | |
$rename | |
$set | |
$setOnInsert | |
$unset |
$ | |
$[] | |
$[<identifier>] | arrayFilters condition for the documents that match the query condition.arrayFilters 条件的所有元素。 |
$addToSet | |
$pop | |
$pull | |
$push | |
$pullAll |
$each | $push and $addToSet operators to append multiple items for array updates.$push 和$addToSet 运算符,以便为数组更新附加多个项。 |
$position | $push operator to specify the position in the array to add elements.$push 运算符以指定数组中要添加元素的位置。 |
$slice | $push operator to limit the size of updated arrays.$push 运算符以限制更新数组的大小。 |
$sort | $push operator to reorder documents stored in an array.$push 运算符以对存储在数组中的文档重新排序。 |
$bit | AND , OR , and XOR updates of integer values.AND 、OR 和XOR 更新。 |