Guest User

Untitled

a guest
Mar 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #installing mongodb
  2. sudo apt-get install mongodb-server
  3.  
  4. #start service
  5. sudo service mongodb start
  6.  
  7. #stop service
  8. sudo service mongodb stop
  9.  
  10. #enter into mongodb console
  11. mongo
  12.  
  13. #show all database
  14. show dbs
  15. admin 0.000GB
  16. local 0.000GB
  17.  
  18. #use or create a databse
  19. > use todo
  20. switched to db todo
  21.  
  22. #show all collection in database
  23. > show collections
  24. todo
  25. >
  26.  
  27. #clear screen
  28. > cls
  29.  
  30. #create a collection
  31. > db.createCollection("list")
  32. { "ok" : 1 }
  33. >
  34. >
  35.  
  36. #insert a document into collection
  37. > db.list.insert({name: "buy groceries from publix"})
  38. WriteResult({ "nInserted" : 1 })
  39.  
  40. > db.list.insert({name: "wash the car and change oil"})
  41. WriteResult({ "nInserted" : 1 })
  42. >
  43.  
  44. #list all document in a collection
  45. > db.list.find()
  46. { "_id" : ObjectId("5a9ff4f2ad855d1ec4a5bc73"), "name" : "buy groceries from publix" }
  47. { "_id" : ObjectId("5a9ff4ffad855d1ec4a5bc74"), "name" : "wash the car and change oil" }
  48.  
  49. #display documents in collection json formatted with pretty()
  50. > db.list.find().pretty()
  51. {
  52. "_id" : ObjectId("5a9ff4f2ad855d1ec4a5bc73"),
  53. "name" : "buy groceries from publix"
  54. }
  55. {
  56. "_id" : ObjectId("5a9ff4ffad855d1ec4a5bc74"),
  57. "name" : "wash the car and change oil"
  58. }
  59. >
  60.  
  61. #remove document from collection
  62. > db.list.remove({name: "buy groceries from publix"})
  63. WriteResult({ "nRemoved" : 1 })
  64. >
  65.  
  66. #drop collection
  67. > db.list.drop()
  68. true
  69. >
  70.  
  71. #drop database
  72. > db.dropDatabase()
  73. { "dropped" : "todo", "ok" : 1 }
  74. >
Add Comment
Please, Sign In to add comment