知乎专栏 |
查找所有 所有记录
db.foo.find() list objects in collection foo db.foo.find( { a : 1 } ) list objects in foo where a == 1
查找一条记录
db.foo.findOne()
根据条件检索10条记录
db.foo.find({'name':'neo'}).limit(10)
sort排序
db.foo.find({'name':'neo'}).sort({'Dt',-1}) db.foo.find().sort({'Ct':-1}).limit(1)
count记录统计操作
db.foo.count()
distinct操作,去重复查询指定列,
db.foo.distinct('name')
”>=”操作
db.foo.find({"timestamp": {"$gte" : 2}})
子对象的查找
db.foo.find({'address.city':'shenzhen'})
db.getCollection('tracker').find({name:"81004892"})