On this page本页内容
$min¶The 如果指定值小于字段的当前值,$min updates the value of the field to a specified value if the specified value is less than the current value of the field. $min将字段的值更新为指定值。The $min operator can compare values of different types, using the BSON comparison order.$min运算符可以使用BSON比较顺序比较不同类型的值。
To specify a 若要在嵌入式文档或数组中指定一个<field> in an embedded document or in an array, use dot notation.<field>,请使用点表示法。
If the field does not exist, the 如果该字段不存在,$min operator sets the field to the specified value.$min运算符将该字段设置为指定值。
For comparisons between values of different types, such as a number and a null, 对于不同类型的值(如数字和空值)之间的比较,$min uses the BSON comparison order.$min使用BSON比较顺序。
$min to Compare Numbers$min来比较数字¶Consider the following document in the collection 在集合scores:scores中考虑以下文档:
The 文档的lowScore for the document currently has the value 200. lowScore当前的值为200。The following operation uses 以下操作使用$min to compare 200 to the specified value 150 and updates the value of lowScore to 150 since 150 is less than 200:$min将200与指定值150进行比较,并将lowScore的值更新为150,因为150小于200:
The scores collection now contains the following modified document:scores集合现在包含以下修改过的文档:
The next operation has no effect since the current value of the field 由于字段lowScore, i.e 150, is less than 250:lowScore(即150)的当前值小于250,因此下一个操作无效:
The document remains unchanged in the 该文档在scores collection:scores集合中保持不变:
$min to Compare Dates$min来比较日期¶Consider the following document in the collection 在集合tags:tags中考虑以下文档:
The following operation compares the current value of the 以下操作将dateEntered field, i.e. ISODate("2013-10-01T05:00:00Z"), with the specified date new Date("2013-09-25") to determine whether to update the field:dateEntered字段的当前值(即ISODate("2013-10-01T05:00:00Z")与指定的日期new Date("2013-09-25")进行比较,以确定是否更新该字段:
The operation updates the 该操作将更新dateEntered field:dateEntered字段:
See also参阅