Docs Home → MongoDB Manual
Query and Projection Operators查询和投影运算符
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表达式的文档。
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
的数值或二进制值。
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.支持跳过和限制切片。
Miscellaneous Operators杂项运算符
Name名称 Description描述
$comment
Adds a comment to a query predicate.向查询谓词添加注释。
$rand
Generates a random float between 0 and 1.生成介于0和1之间的随机浮点数。