||| |
最近有用到mongdb语句,特此记录下,已备今后的回顾复习。
mongdb的查询语句和sql不同,将语法记录下来,备用。
左边是mongodb查询语句,右边是sql语句。对照着用,挺方便。
mongodb sql
db.users.find() select * from users
db.users.find({"age" :27}) select * from users where age =27
db.users.find({"username" :"joe","age" :27}) select * from users where"username" ="joe" and age =27
db.users.find({}, {"username" :1,"email" :1}) select username, email from users
db.users.find({"age" : {"$gte" :18,"$lte" :30}}) select * from users where age >=18 and age <=30
db.users.find({"username" : {"$ne" :"joe"}}) select * from users where username <>"joe"
db.users.find({"ticket_no" : {"$in" : [725,542,390]}}) select * from users where ticket_no in (725,542,390)
db.users.find({"ticket_no" : {"$nin" : [725,542,390]}}) select * from users where ticket_no not in (725,542,390)
db.users.find({"$or" : [{"ticket_no" :725}, {"winner" :true}]}) select * form users where ticket_no =725 or winner =true
db.users.find({"id_num" : {"$mod" : [5,1]}}) select * from users where (id_num mod5) =1
db.users.find({"$not": {"age" :27}}) select * from users where not (age =27)
db.users.find({"username" : {"$in" : [null],"$exists" :true}}) select * from users where username is null
本文转载自https://www.jianshu.com/p/e3ca154d3e54
写此篇文章的目的仅仅是想用来备份
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-24 22:14
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社