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描述
$eq Matches values that are equal to a specified value.匹配等于指定值的值。
$gt Matches values that are greater than a specified value.匹配大于指定值的值。
$gte Matches values that are greater than or equal to a specified value.匹配大于或等于指定值的值。
$in Matches any of the values specified in an array.匹配数组中指定的任何值。
$lt Matches values that are less than a specified value.匹配小于指定值的值。
$lte Matches values that are less than or equal to a specified value.匹配小于或等于指定值的值。
$ne Matches all values that are not equal to a specified value.匹配所有不等于指定值的值。
$nin Matches none of the values specified in an array.不匹配数组中指定的任何值。

Logical逻辑

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

Element元素

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

Evaluation评估值

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

Geospatial地理空间

Name名称Description描述
$geoIntersects Selects geometries that intersect with a GeoJSON geometry.选择与GeoJSON几何图形相交的几何图形。The 2dsphere index supports $geoIntersects.2dsphere索引支持$geoIntersects
$geoWithin Selects geometries within a bounding GeoJSON geometry.选择边界几何图形中的几何图形。The 2dsphere and 2d indexes support $geoWithin.2dsphere2d索引支持$geoWithin
$near Returns geospatial objects in proximity to a point.返回点附近的地理空间对象。Requires a geospatial index. 需要地理空间索引。The 2dsphere and 2d indexes support $near.2dsphere2d索引支持$near
$nearSphere Returns 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描述
$all Matches arrays that contain all elements specified in the query.匹配包含查询中指定的所有元素的数组。
$elemMatch Selects documents if element in the array field matches all the specified $elemMatch conditions.如果数组字段中的元素与所有指定的$elemMatch条件匹配,则选择文档。
$size Selects documents if the array field is a specified size.如果数组字段为指定大小,则选择文档。

Bitwise按位

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

Comments评论

Name名称Description描述
$comment Adds a comment to a query predicate.向查询谓词添加注释。

Projection Operators投影运算符

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