查询所有 |
MongoDB |
db.getCollection(‘user’).find({}); |
|
MySQL |
select * from user; |
查询条件:= |
MongoDB |
db.getCollection(‘user’).find({“age”:16});等效于db.getCollection(‘user’).find({“age”:{$eq:16}}); |
|
MySQL |
select * from user where age = 16; |
查询条件:like |
MongoDB |
db.getCollection(‘user’).find({“name”:/Ba/}); |
|
MySQL |
select * from user where name like ‘%Ba%’; |
查询条件:distinct |
MongoDB |
db.getCollection(‘user’).distinct(“name”); |
|
MySQL |
select distinct uclass from user u; |
查询条件:> |
MongoDB |
db.getCollection(‘user’).find({“age”:{$gt:16}}); |
|
MySQL |
select * from user where age >16; |
查询条件:>= |
MongoDB |
db.getCollection(‘user’).find({“age”:{$gte:16}}); |
|
MySQL |
select * from user where age >= 16; |
查询条件:< |
MongoDB |
db.getCollection(‘user’).find({“age”:{$lt:16}}); |
|
MySQL |
select * from user where age < 16; |
查询条件:<= |
MongoDB |
db.getCollection(‘user’).find({“age”:{$lte:16}}); |
|
MySQL |
select * from user where age 16; |
查询条件:or |
MongoDB |
db.getCollection(‘user’).find({$or:[{“uclass”:”A”},{“class”:”B”}]}); |
|
MySQL |
select * from user where uclass = ‘A’ or uclass = ‘B’; |
查询条件:时间 |
MongoDB |
db.getCollection(‘user’).find({“birthday”:{$gt: new Date(“2008-08-14T06:24:40.110Z”), $lt: new Date(“2015-08-14T06:14:40.089Z”)}}); |
|
MySQL |
select * from user where birthday > ‘2008-08-14 06:24:40’ and birthday < ‘2015-08-14 06:14:40’; |
查询条件:count |
MongoDB |
db.getCollection(‘user’).find({“uclass”:”A”}).count(); |
|
MySQL |
select count(1) from user where uclass = ‘A’; |
查询条件:sort升序 |
MongoDB |
db.getCollection(‘user’).find({}).sort({“age”:1}); |
|
MySQL |
select * from user order by age asc; |
查询条件:sort降序 |
MongoDB |
db.getCollection(‘user’).find({}).sort({“age”:-1}); |
|
MySQL |
select * from user order by age desc; |