原帖,请参看这里。
官网:https://docs.mongodb.com/manual/reference/operator/query/。
这一章节都是很简单的英语,就做一个很简单的备注,如果连这个英语都看不懂,那就需要提高了,程序员看不懂基本的英语是很难提高的。
这一章节还需要完善一些样例,这个有待补充。
查询选择器
比较
| 名字 |
描述 |
| $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.(判断不在其中) |
逻辑
| 名字 |
描述 |
| $and |
Joins query clauses with a logical AND returns all documents that match the conditions of both clauses.(与) |
| $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.(异或) |
| $or |
Joins query clauses with a logical OR returns all documents that match the conditions of either clause.(或) |
元素
| 名字 |
描述 |
| $exists |
Matches documents that have the specified field. |
| $type |
Selects documents if a field is of the specified type. |
评估
| 名字 |
描述 |
| $expr |
Allows use of aggregation expressions within the query language. |
| $jsonSchema |
Validate documents against the given JSON Schema. |
| $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. |
地理空间
| 名字 |
描述 |
| $geoIntersects |
Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects. |
| $geoWithin |
Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. |
| $near |
Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near. |
| $nearSphere |
Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere. |
数组
| 名字 |
描述 |
| $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. |
| $size |
Selects documents if the array field is a specified size. |
位操作
| 名字 |
描述 |
| $bitsAllClear |
Matches numeric or binary values in which a set of bit positions all have a value of 0. |
| $bitsAllSet |
Matches numeric or binary values in which a set of bit positions all have a value of 1. |
| $bitsAnyClear |
Matches numeric or binary values in which any bit from a set of bit positions has a value of 0. |
| $bitsAnySet |
Matches numeric or binary values in which any bit from a set of bit positions has a value of 1. |
注释
| 名字 |
描述 |
| $comment |
Adds a comment to a query predicate. |
投影操作
| 名字 |
描述 |
| $ |
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. |
| $meta |
Projects the document’s score assigned during $text operation. |
| $slice |
Limits the number of elements projected from an array. Supports skip and limit slices. |