Created
August 21, 2017 06:29
-
-
Save akankshach29/eace290931cbfc23d102744cf13024c4 to your computer and use it in GitHub Desktop.
Mongo DB commands frequently used
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment