mongoDB简单语句

来源:互联网 发布:java erp开发教程 编辑:程序博客网 时间:2024/06/08 06:09

自己整理了一些mongoDB日常会用到的语句,

sqlmongoselect * from lhcdb.lhc.find()select * from lhc limit 1db.lhc.findOne()
db.lhc.find().limit(1)select id,name from lhcdb.lhc.find({},{"id":1,"name":1})select * from lhc where age=33db.lhc.find({"age":33})select * from lhc where age=33 and name='luo huichao'db.lhc.find({"age":33,"name":"luo huichao"})select * from lhc where age=33 or age=50db.lhc.find({"$or":[{"age":33},{"age":50}]})select id,name from lhc where age=33db.lhc.find({"age":33},{"id":1,"name":1})select * from lhc where age=33 order by namedb.lhc.find({"age":33}).sort({"name":1})select * from lhc where age>33db.lhc.find({"age":{"$gt":33}})
db.lhc.find({"age":{"$ge":33}}) >=
db.lhc.find({"age":{"$le":33}})<=select * from lhc where age>=33 and age<50db.lhc.find({"age":{"$ge":33,"$lt":50}})select * from lhc where age!=33db.lhc.find({"age":{"$ne":33}})
db.lhc.find({"age":{"$eq":33}})=select * from lhc where name like '%luo%'db.lhc.find({"name":/luo/})
db.lhc.find({"name":/^luo/}) like 'luo%select * from lhc where age in(33,44)db.lhc.find({"age":{"$in":[33,44]}})
db.lhc.find({"age":{"$nin":[33,44]}}) not inselect distinct name from lhc db.lhc.distinct("name")select * from lhc where name is nulldb.lhc.find({"name":{"$exists":false}})
如果有补充,请在下面顶上!!!

原创粉丝点击