Query and Projection Operators查询和投影运算符

On this page本页内容

Note注意

For details on specific operator, including syntax and examples, click on the specific operator to go to its reference page.有关特定运算符的详细信息,包括语法和示例,请单击特定运算符以转到其参考页。

Query Selectors查询选择器

Comparison比较

For comparison of different BSON type values, see the specified BSON comparison order.有关不同BSON类型值的比较,请参阅指定的BSON比较顺序

Name名称Description描述
$eqMatches values that are equal to a specified value.匹配等于指定值的值。
$gtMatches values that are greater than a specified value.匹配大于指定值的值。
$gteMatches values that are greater than or equal to a specified value.匹配大于或等于指定值的值。
$inMatches any of the values specified in an array.匹配数组中指定的任何值。
$ltMatches values that are less than a specified value.匹配小于指定值的值。
$lteMatches values that are less than or equal to a specified value.匹配小于或等于指定值的值。
$neMatches all values that are not equal to a specified value.匹配所有不等于指定值的值。
$ninMatches none of the values specified in an array.不匹配数组中指定的任何值。

Logical逻辑

Name名称Description描述
$andJoins query clauses with a logical AND returns all documents that match the conditions of both clauses.将查询子句AND逻辑连接起来,并返回与这两个子句的条件匹配的所有文档。
$notInverts the effect of a query expression and returns documents that do not match the query expression.反转查询表达式的效果,并返回与查询表达式匹配的文档。
$norJoins query clauses with a logical NOR returns all documents that fail to match both clauses.使用逻辑NOR连接查询子句,返回所有未能同时匹配这两个子句的文档。
$orJoins query clauses with a logical OR returns all documents that match the conditions of either clause.将查询子句与逻辑OR联接,返回与任一子句的条件匹配的所有文档。

Element元素

Name名称Description描述
$existsMatches documents that have the specified field.匹配具有指定字段的文档。
$typeSelects documents if a field is of the specified type.如果字段为指定类型,则选择文档。

Evaluation估值

Name名称Description描述
$exprAllows use of aggregation expressions within the query language.允许在查询语言中使用聚合表达式。
$jsonSchemaValidate documents against the given JSON Schema.根据给定的JSON模式验证文档。
$modPerforms a modulo operation on the value of a field and selects documents with a specified result.对字段的值执行模运算,并选择具有指定结果的文档。
$regexSelects documents where values match a specified regular expression.选择值与指定正则表达式匹配的文档。
$textPerforms text search.执行文本搜索。
$whereMatches documents that satisfy a JavaScript expression.匹配满足JavaScript表达式的文档。

Geospatial地理空间

Name名称Description描述
$geoIntersectsSelects geometries that intersect with a GeoJSON geometry. 选择与GeoJSON几何图形相交的几何图形。The 2dsphere index supports $geoIntersects.2dsphere索引支持$geoIntersects
$geoWithinSelects geometries within a bounding GeoJSON geometry. 选择边界GeoJSON几何图形中的几何图形。The 2dsphere and 2d indexes support $geoWithin.2dsphere2d索引支持$geoWithin
$nearReturns geospatial objects in proximity to a point. 返回点附近的地理空间对象。Requires a geospatial index. 需要地理空间索引。The 2dsphere and 2d indexes support $near.2dsphere2d索引支持$near
$nearSphereReturns geospatial objects in proximity to a point on a sphere. 返回球体上某个点附近的地理空间对象。Requires a geospatial index. 需要地理空间索引。The 2dsphere and 2d indexes support $nearSphere.2dsphere2d索引支持$nearSphere

Array数组

Name名称Description描述
$allMatches arrays that contain all elements specified in the query.匹配包含查询中指定的所有元素的数组。
$elemMatchSelects documents if element in the array field matches all the specified $elemMatch conditions.如果数组字段中的元素与所有指定的$elemMatch条件匹配,则选择文档。
$sizeSelects documents if the array field is a specified size.如果数组字段为指定大小,则选择文档。

Bitwise

Name名称Description描述
$bitsAllClearMatches numeric or binary values in which a set of bit positions all have a value of 0.匹配一组位位置均为0的数值或二进制值。
$bitsAllSetMatches numeric or binary values in which a set of bit positions all have a value of 1.匹配数字或二进制值,其中一组位位置的值均为1
$bitsAnyClearMatches numeric or binary values in which any bit from a set of bit positions has a value of 0.匹配一组位位置中任何位的值为0的数值或二进制值。
$bitsAnySetMatches numeric or binary values in which any bit from a set of bit positions has a value of 1.匹配一组位位置中任何位的值为1的数值或二进制值。

Projection Operators投影运算符

Name名称Description描述
$Projects the first element in an array that matches the query condition.投影数组中与查询条件匹配的第一个元素。
$elemMatchProjects the first element in an array that matches the specified $elemMatch condition.投影数组中与指定的$elemMatch条件匹配的第一个元素。
$metaProjects the document's score assigned during $text operation.投影在$text操作期间指定的文档分数。
$sliceLimits the number of elements projected from an array. 限制从数组投影的元素数。Supports skip and limit slices.支持跳过和限制切片。

Miscellaneous Operators杂项运算符

Name名称Description描述
$commentAdds a comment to a query predicate.向查询谓词添加注释。
$randGenerates a random float between 0 and 1.生成介于0和1之间的随机浮点数。
←  OperatorsComparison Query Operators →