標籤:select 常用 tick lte ble rom enter table mon
mongo |
sql |
說明 |
db.users.find() |
select * from users |
從user表中查詢所有資料 |
db.users.find({“username” : “joe”, “age” : 27}) |
select * from users where “username” = “joe” and age = 27 |
尋找username = joe且age = 27的人 |
db.users.find({}, {“username” : 1, “email” : 1}) |
select username, email from users |
尋找username,email這2個子項 |
db.users.find({“age” : {“$gt” : 18}}) |
select * from users where age >18 |
尋找age > 18的會員 |
db.users.find({“age” : {“$gte” : 18}}) |
select * from users where age >=18 |
尋找age >= 18的人 |
db.users.find({“age” : {“$lt” : 18}}) |
select * from users where age <18 |
尋找age < 18的人 |
db.users.find({“age” : {“$lte” : 18}}) |
select * from users where age <=18 |
尋找age <= 18的人 |
db.users.find({“username” : {“$ne” : “joe”}}) |
select * from users where username <> “joe” |
尋找 username != joe的會員 |
db.users.find({“ticket_no” : {“$in” : [725, 542, 390]}}) |
select * from users where ticket_no in (725, 542, 390) |
符合tickt_no在此範圍的結果 |
db.users.find({“ticket_no” : {“$nin” : [725, 542, 390]}}) |
select * from users where ticket_no not in (725, 542, 390) |
符合tickt_no不在此範圍的結果 |
db.users.find({“name” : /joey^/}) |
select * from users where name like “joey%” |
尋找前4個字元為joey的人 |
mongodb常用查詢