Skip to content

Instantly share code, notes, and snippets.

@dvigneshwer
Created February 7, 2018 14:28
Show Gist options
  • Save dvigneshwer/d7a76998482e6319cdf2c105b092ffe0 to your computer and use it in GitHub Desktop.
Save dvigneshwer/d7a76998482e6319cdf2c105b092ffe0 to your computer and use it in GitHub Desktop.
Useful MongoDB commands | More like a cheatsheet for easy reference

Create DB

use dataase_name

You will have to insert a value inorder for the db to get showcased in show dbs command.

Show Commands

show dbs # To see all the database names

show collections # To see all the collection names 
db.getCollectionNames()

Creating & Inserting key-value in a Collections

db.createCollection("NameOfTheCollection")

# Automatically adds an id to the document
db.createCollection("NameOfTheCollection", {autoIndexId : true})

db.NameOftheCollection.insert({"key":"value"})

To see the content of the collections

db.collectionName.find()
db.collectionName.find().pretty()

db.collectionName.find({key : {$eq : value}}).pretty() # Search for a particular key

db.AutoIDActor.count() # Count the number of collections 

Will make this list more comprehensive on the fly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment