On this page本页内容
$min
¶Deprecated since v3.2
Starting in v3.2, the $min
operator is deprecated in the mongo
shell. In the mongo
shell, use cursor.min()
instead.
Specify a $min
value to specify the inclusive lower bound for a specific index in order to constrain the results of find()
. The $min
specifies the lower bound for all keys of a specific index in order.
The mongo
shell provides the min()
wrapper method:mongo
shell提供了min()
包装方法:
You can also specify the option with either of the two forms:还可以使用以下两种形式之一指定选项:
Because min()
requires an index on a field, and forces the query to use this index, you may prefer the $gte
operator for the query if possible. Consider the following example:
The query will use the index on the 查询将使用age
field, even if the index on _id
may be better.age
字段上的索引,即使_id
上的索引可能更好。
$min
without $max
¶The min
and max
operators indicate that the system should avoid normal query planning. Instead they construct an index scan where the index bounds are explicitly specified by the values given in min
and max
.
Warning
If one of the two boundaries is not specified, the query plan will be an index scan that is unbounded on one side. 如果未指定两个边界中的一个,则查询计划将是一侧无边界的索引扫描。This may degrade performance compared to a query containing neither operator, or one that uses both operators to more tightly constrain the index scan.与既不包含运算符,也不使用两个运算符来更严格地约束索引扫描的查询相比,这可能会降低性能。
The following examples use the 以下示例使用mongo
shell wrappers.mongo
shell包装器。
Consider the following operations on a collection named 考虑一个名为collection
that has an index { age: 1 }
:collection
的集合的以下操作,该集合具有索引{age:1 }
:
This operation limits the query to those documents where the field age
is at least 20
and forces a query plan which scans the { age: 1 }
index from 20 to MaxKey.