Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // ----------------------------- general -----------------------
  2.  
  3. db // show current database
  4. show dbs // dhow all databases
  5. use DB_NAME // create or switch to database
  6. show collections // show all collections inside a database
  7. db.runCommand({dropDatabase:1}) // drop current database
  8.  
  9. // ----------------------------- Find -----------------------
  10.  
  11. db.test.findOne() // display one randmly
  12. db.test.find() // diplay all
  13. db.test.find({nom:"smith"},{nom:true,age:true}) // first object is like WHERE 2nd is WHAT TO DISPLAY
  14.  
  15. db.test.find({"age":27}) // select * from test where age=27
  16. db.test.find({},{"nom":1,"age":1}) // select nom,age from test
  17. db.test.find({},{"nom":0}) // select age,profession from test
  18.  
  19. db.test.find({"age":{"$gte":18,"$lte":30}}) // select * from test where age between 18 and 30
  20. db.test.find({"num":{"$in":[151,254,587]}}) // select * from test where num in (151,254,587)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement