Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Here’s a cheat sheet of Mongo Shell commands often used:
- 1 Login to the server
- 2 Type `mongo` to get the mongo terminal
- To create a new database:
- use database_name
- To See the list of all database present:
- show dbs
- To use the database you want to use:
- use <dbname>
- To see all Collections(group of MongoDB documents) in current database:
- show collections
- To see all the data present in db:
- db.collectionname.find({}).pretty()
- To count the existence of a particular data:
- db.collectionname.find({"title" : “Some data”}).count()
- To find a document:
- db.collectionname.find({"title" : “Some data" }).pretty()
- To update a single document:
- db.collectionname.update({"title" : “Some data" }, { $set: {"title": “New data”}})
- To update multiple documents at once:
- db.collectionname.update({"title" : “Some data" }, { $set: {"title": “New data"}}, {"multi": true})
- To remove any document:
- db.collectionname.remove({"title" : “Some data”})
- To remove documents not equal to “Some data”:
- db.collectionname.remove({"title" : { $ne : “Some data"}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement