查询,更新, 以及投影算符快速参考

This document contains a list of all operators used with MongoDB in version 2.2.3. See 核心操作(CRUD) for a higher level overview of the operations that use these operators, and 查询, 更新, 投射, 和集合算符 for a more condensed index of these operators.

查询选择器

比较

注解

To express equal to (e.g. =) in the MongoDB query language, use JSON { key:value } structure. Consider the following prototype:

db.collection.find( { field: value } )

For example:

db.collection.find( { a: 42 } )

This query selects all the documents the where the a field holds a value of 42.

You may combine comparison operators to specify ranges:

db.collection.find( { field: { $gt: value1, $lt: value2 } } );

This statement returns all documents with field between value1 and value2.

注解

Fields containing arrays match conditional operators, if only one item matches. Therefore, the following query:

db.collection.find( { field: { $gt:0, $lt:2 } } );

Will match a document that contains the following field:

{ field: [-1,3] }

逻辑

JavaScript