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的人 |