查询条件的关系运算
-
相等
查询年龄等于10岁的信息
db.stu.find({age:10});
KaTeX parse error: Expected '}', got 'EOF' at end of input: …stu.find({age:{eq:10}}); -
大于
KaTeX parse error: Expected '}', got 'EOF' at end of input: …stu.find({age:{gt:20}});
大于等于
$gte: (greater than or equal)
-
小于
$lt: (less than)
小于等于
$lte -
不等于
KaTeX parse error: Expected '}', got 'EOF' at end of input: …stu.find({age:{ne:20}});
逻辑关系
- 与
查询年龄为18,并且性别为女的信息
db.stu.find({age:18,sex:“女”})
查询年龄大于20岁,并且性别为女的信息
db.stu.find({age:{$gt:20},sex:“女”});
$and
db.stu.find({ KaTeX parse error: Expected '}', got 'EOF' at end of input: and:[{age:{gt:20}},{sex:“F”}] });
数组中的条件必须全都满足
-
或
$or
查询年龄大于20岁或性别为F的信息
db.stu.find({ KaTeX parse error: Expected '}', got 'EOF' at end of input: or:[{age:{gt:20}},{sex:“F”}] });
数组中的条件只需要满足其中之一即可 -
非
KaTeX parse error: Expected '}', got 'EOF' at end of input: …stu.find({age:{not:{$gt:20}}}); -
既不也不
KaTeX parse error: Expected '}', got 'EOF' at end of input: …息 db.stu.find({nor:[{age:{$gt:20}},{sex:“F”}]});
数组中的条件只要满足其一,就不要