Inert into users value (3,5) |
Db.users.insert ({a:3,b:5}) |
|
|
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 the 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:{$ne: 33}}) |
SELECT * from the users where name like "%joe%" |
Db.users.find ({name:/joe/}) |
SELECT * from the users where name like "joe%" |
Db.users.find ({name:/^joe/}) |
SELECT * from users where age>33 and age<=40 |
Db.users.find ({' age ': {$gt:, $lte: 40}}) |
SELECT * from Users ORDER BY name Desc |
Db.users.find (). Sort ({name:-1}) |
SELECT * from users where a=1 and b= ' Q ' |
Db.users.find ({a:1,b: ' Q '}) |
SELECT * from users limit skip 20 |
Db.users.find (). Limit (Ten). 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 () |
Select order_id from Orders o, Order_line_items Li where li.order_id=o.order_id and li.sku=12345 |
Db.orders.find ({"Items.sku": 12345},{_id:1}) |
Select Customer.name from Customers,orders where orders.id= "q179" and Orders.custid=customer.id |
var o = Db.orders.findOne ({_id: "q179"}); var name = Db.customers.findOne ({_id:o.custid}) |
|
|
Select DISTINCT last_name from users |
Db.users.distinct (' last_name ') |
Select COUNT (*y) From users |
Db.users.count () |
Select COUNT (*y) From the users where age > 30 |
Db.users.find ({age: {' $GT ': $}}). Count () |
Select count (age) from users |
Db.users.find ({age: {' $exists ': true}}). Count () |
|
|
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}) |
|
|
Explain select * from users where z=3 |
Db.users.find ({Z:3}). Explain () |
|
|
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 '}); |