mongo常用查询语法

mongodb 时间范围查询

db.posts.find({created_on: {$gte: start, $lt: end}});

db.mmb_chekin.findOne({‘add_time’:{‘ g t e : 1492358400 , gte': 1492358400, ' lt’: 1492444800} })

模糊查询:tname包含某个关键字测试’

cd /opt/soft/mongodb/bin
./mongo --host 192.168.0.1 --port 17017 test
db.test_info.find({“tname”: {$regex: ‘测试’, KaTeX parse error: Expected 'EOF', got '}' at position 12: options:'i'}̲}) db.test_inf…regex:/测试.*/i}})

or查询:

db.tianyc02.find({KaTeX parse error: Expected 'EOF', got '}' at position 23: …e:11},{age:22}]}̲) db.tianyc02.f…or:[{age:11},{name:‘xttt’}]})

查询某个字段是否存在

db.course.find( { “lectures.lectures_count”: { KaTeX parse error: Expected 'EOF', got '}' at position 14: exists: true }̲ } ) db.feeds.f…exists’: true }})
db.users.find({‘circles.status’:{’$exists’: true }},{‘circles’:1}).count()

distinct
db.users.distinct(’_id’,{}).length

最大值

mongo客户端命令行登录,如果连的是从库,链接要先输入 rs.slaveOk()

指定find查询每次返回的记录数:DBQuery.shellBatchSize = xxx
注:python里不需要指定返回记录数,for xx in xx.find()会遍历所有结果

猜你喜欢

转载自blog.csdn.net/Eos0422/article/details/89135063