用JSON数据格式来查询,跟MYSQL查询区别:字符串跟N维数组的区别。
AND 多条件判断查询
db.stu.find({"age":{$ne:21, $exists:1}, "name":"rubby"})
GROUP分组聚合
db.stu.aggregate([{
$match: {
"age": {
$exists: 1
}
}
}, {
$group: {
_id: "$age",
num: {
$sum: 1
}
}
}])
简化版: db.stu.aggregate([{$match:{"age":{$exists:1}}},{$group:{_id:"$age", num:{$sum:1}}}])