经常使用的mongodb命令

 

以下演示collection是集合名

以key为基准去重查看
db.collection.distinct("keyname")

查询命令

等于
db.collection.find({"name": "jack"})

小于
查询小于10的数据
db.collection.find({"count":{$lt: 10}})

小于或等于
查询大于10的数据
db.collection.find({"count":{$lte:10}})

大于
查询大于10的数据
db.collection.find({"count": {$gt: 10}})

大于或等于
查询大于等于10的数据
db.collection.find({"count": {$gte:10}})

不等于
查询不等于10的数据
db.collection.find({"count": {$ne: 10}})

美化输出
pretty()
db.collection.find({"name": "jack"}).pretty()

and 条件
mongodb的find()方法可以传入多个键,每个键(key)以逗号隔开
db.collection.find({"name":"jack", "age": 18})

or 条件
mongodb or 条件语句使用了关键字$or
db.collection.find({$or: [{"name": "jack", {"name": "peter"}}]})

原文地址:https://www.cnblogs.com/onesea/p/13405184.html