基本语法:
db.collection.find({<key>:{$symbol:<value>}})
mongodb
符号 | 描述 | 范例 | js释义 |
---|---|---|---|
$eq |
等于 | {qty:{$eq:2}} or {qty:2} |
qty===2 |
$gt |
大于 | {qty:{$gt:2}} |
qty>2 |
$gte |
大于或等于 | {qty:{$gte:2}} |
qty>=2 |
$lt |
小于 | {qty:{$lt:2}} |
qty<2 |
$lte |
小于或等于 | {qty:{$lte:2}} |
qty<=2 |
$ne |
不等于 | {qty:{$ne:2}} |
qty!=2 |
$in |
查询等于指定数组中任何值的数据 | {qty:{$in:[5,2,3]}} |
qty===5 || qty===2 || qty===3 |
$nin |
查询不等于指定数组中任何值数据 | {qty:{$nin:[5,2,3]}} |
qty!=5 || qty!=2 || qty!=3 |
$and
逻辑且
{$and:[{<expression1>}, {<expression2>}, ... ,{<expressionN>}]}
{$and:[{qty:{$ne:2}},{"name":{$eq:"测试"}}]}
qty!=2 && "name"==="测试"
$not
逻辑非
{<key>:{$not:{<operator-expression>}}}
{price:{$not:{$gt:1.99}}}
!(price>1.99)
$nor
逻辑非或
{$nor:[{<expression1>}, {<expression2>}, ...,{<expressionN>}]}
{$nor:[{price:1.99}, {sale:true}]}
!(price===1.99||sale===true)
$or
逻辑或
{$or:[{<expression1>}, {<expression2>}, ...,{<expressionN>}]}
{$or:[qty:{$lt:20}}, {price:10}]}
qty<20 || price===10
$exists
查询值是否存在
{<key>:{$exists:<boolean>}}
{qty:{$exists:true, $nin:[ 5, 15 ]}}
qty && (qty!=5 || qty!=15)
$type
检测值的类型
{<key>:{$type:<BSON type>}}
{"zipCode":{$type:2}}}
or {"zipCode":{$type:"string"}}}
typeof "zipCode" === "string"