SQL statement |
Mongo query language statement |
Create Table users (a number, B Number) |
dB. createcollection ( " mycoll ", {capped: true , size: 100000 }) |
Insert into users values (1, 1) |
DB. Users. insert ({A: 1, B: 1 }) |
Select a, B from users |
DB. Users. Find ({}, {A: 1, B: 1 }) |
Select * from users |
DB. Users. Find () |
Select * from users where age = 33 |
DB. Users. Find ({age: 33 }) |
Select a, B from users where age = 33 |
DB. Users. Find ({age: 33}, {A: 1, B: 1 }) |
Select * from users where age = 33 order by name |
DB. Users. Find ({age: 33}). Sort ({Name: 1 }) |
Select * from users where age> 33 |
DB. Users. Find ({'age': {$ GT: 33 }})}) |
Select * from users where age <33 |
DB. Users. Find ({'age': {$ LT: 33 }})}) |
Select * from users where name like "% Joe %" |
DB. Users. Find ({Name:/Joe /}) |
Select * from users where name like "Joe %" |
DB. Users. Find ({Name:/^ Joe /}) |
Select * from users where age> 33 and age <= 40 |
DB. Users. Find ({'age': {$ GT: 33, $ LTE: 40 }})}) |
Select * from users order by name DESC |
DB. Users. Find (). Sort ({Name:-1 }) |
Create index myindexname on users (name) |
DB. Users. ensureindex ({Name: 1 }) |
Create index myindexname on users (name, ts desc) |
DB. Users. ensureindex ({Name: 1, TS:-1 }) |
Select * from users where a = 1 and B = 'Q' |
DB. Users. Find ({A: 1, B: 'q '}) |
Select * from users limit 10 skip 20 |
DB. Users. Find (). Limit (10). Skip (20) |
Select * from users where a = 1 or B = 2 |
DB. Users. Find ({$ or: [{A: 1 },{ B: 2}]}) |
Select * from users limit 1 |
DB. Users. findone () |
Explain select * from users where z = 3 |
DB. Users. Find ({z: 3}). Explain () |
Select distinct last_name from users |
DB. Users. Distinct ('Last _ name ') |
Select count (* Y) From Users |
DB. Users. Count () |
Select count (* Y) From users where age> 30 |
DB. Users. Find ({age: {'$ GT': 30}). Count () |
Select count (AGE) from users |
DB. Users. Find ({age: {'$ exists': true}). Count () |
Update users set a = 1 Where B = 'Q' |
DB. Users. Update ({B: 'q'}, {$ set: {A: 1 }}, false, true) |
Update users set a = a + 2 Where B = 'Q' |
DB. Users. Update ({B: 'q'}, {$ Inc: {A: 2 }}, false, true) |
Delete from users where z = "ABC" |
dB. users. remove ({z: 'abc'}); |