Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. Mongo DB unlike relational database, is a JSON-like document oriented database. The mongo shell is an interface used to add, query, update, etc data.
  2. Here’s a cheat sheet of Mongo Shell commands often used:
  3.  
  4. 1 Login to the server
  5. 2 Type `mongo` to get the mongo terminal
  6.  
  7. To create a new database:
  8. use database_name
  9.  
  10. To See the list of all database present:
  11. show dbs
  12.  
  13. To use the database you want to use:
  14. use <dbname>
  15.  
  16. To see all Collections(group of MongoDB documents) in current database:
  17. show collections
  18.  
  19. To see all the data present in db:
  20. db.collectionname.find({}).pretty()
  21.  
  22. To count the existence of a particular data:
  23. db.collectionname.find({"title" : “Some data”}).count()
  24.  
  25. To find a document:
  26. db.collectionname.find({"title" : “Some data" }).pretty()
  27.  
  28. To update a single document:
  29. db.collectionname.update({"title" : “Some data" }, { $set: {"title": “New data”}})
  30.  
  31. To update multiple documents at once:
  32. db.collectionname.update({"title" : “Some data" }, { $set: {"title": “New data"}}, {"multi": true})
  33.  
  34. To remove any document:
  35. db.collectionname.remove({"title" : “Some data”})
  36.  
  37. To remove documents not equal to “Some data”:
  38. db.collectionname.remove({"title" : { $ne : “Some data"}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement