查询
查询所有
db.collection.find()
获取数据条数
db.collection.find().count()
范围查询
查询age>22的记录
db.userInfo.find((age:{$gt:22}});
查询age<22的记录
db.userInfo.find({age:{$lt:22}});
查询age>=25的记录
db.userInfo.find({age:{$gte:25}});
查询age<=25的记录
db.userInfo.find({age:{$lte:25}});
查询age>23并且age<=26
db.userInfo.find({age:{gte:23,$lte:26}});
and
查询student 集合中名字为zs且id为02的项:
db.getCollection("student").find({"name":"zs","id":"02"})
查询集合中指定字段的所有不同值
db.目标集合.distinct("指定字段")
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 changzeyan@foxmail.com