Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #installing mongodb
- sudo apt-get install mongodb-server
- #start service
- sudo service mongodb start
- #stop service
- sudo service mongodb stop
- #enter into mongodb console
- mongo
- #show all database
- show dbs
- admin 0.000GB
- local 0.000GB
- #use or create a databse
- > use todo
- switched to db todo
- #show all collection in database
- > show collections
- todo
- >
- #clear screen
- > cls
- #create a collection
- > db.createCollection("list")
- { "ok" : 1 }
- >
- >
- #insert a document into collection
- > db.list.insert({name: "buy groceries from publix"})
- WriteResult({ "nInserted" : 1 })
- > db.list.insert({name: "wash the car and change oil"})
- WriteResult({ "nInserted" : 1 })
- >
- #list all document in a collection
- > db.list.find()
- { "_id" : ObjectId("5a9ff4f2ad855d1ec4a5bc73"), "name" : "buy groceries from publix" }
- { "_id" : ObjectId("5a9ff4ffad855d1ec4a5bc74"), "name" : "wash the car and change oil" }
- #display documents in collection json formatted with pretty()
- > db.list.find().pretty()
- {
- "_id" : ObjectId("5a9ff4f2ad855d1ec4a5bc73"),
- "name" : "buy groceries from publix"
- }
- {
- "_id" : ObjectId("5a9ff4ffad855d1ec4a5bc74"),
- "name" : "wash the car and change oil"
- }
- >
- #remove document from collection
- > db.list.remove({name: "buy groceries from publix"})
- WriteResult({ "nRemoved" : 1 })
- >
- #drop collection
- > db.list.drop()
- true
- >
- #drop database
- > db.dropDatabase()
- { "dropped" : "todo", "ok" : 1 }
- >
Add Comment
Please, Sign In to add comment