Please enable Javascript to correctly display the contents on Dot Net Tricks!

Mongo Shell Commonly Used Commands and Methods Quick Reference

  Author : Shailendra Chauhan
Updated On : 29 May 2015
Total Views : 4,371   
 

MongoDB shell is an interactive JavaScript shell which help you to manage a MongoDB server. It provides a set of commands to create, update, delete and query your mongodb database. Here is a list of commonly used commands and methods.

Command Helpers

Methods and Commands
Description
help
Show list of commonly used methods and commands with description
db.help()
Show a list of database methods with description
db.<collection>.help()
Show help on collection methods. The <collection_name> can be the name of an existing collection or a non-existing collection.
show dbs / show databases
Show a list of all mongodb databases on the server
use <db_name>
Switch from current database to <db_name>
show collections
Show a list of all collections for current database
show users
Show a list of all users for current database
show roles
Show a list of all user-defined and built-in roles for current database

Basic Shell JavaScript Operations

Operations
Description
db.<collection_name>.find()
Find all documents in the collection
db.<collection_name>.insert()
Insert a new document into the collection
db.<collection_name>.update()
Update an existing document in the collection.
db.<collection_name>.save()
Insert either a new document or update an existing document in the collection
db.<collection_name>.remove()
Delete all documents from the collection
db.<collection_name>.drop()
Completely Drops or removes the collection
db.<collection_name>.createIndex()
Create a new index on the collection if the index does not exist otherwise, the operation has no effect
What do you think?
That’s it for now! I hope you get a good idea of Mongo shell commands. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.


YOU MIGHT LIKE
Free Interview Books
 
COMMENTS (0)
13 FEB
ASP.NET Core Development (online)

07:00 AM-09:00 AM IST( MON, WED, FRI)

Know More
25 JAN
Angular2 and Angular1 Development (online)

09:00 PM-10:30 PM IST(MON-FRI)

Know More
24 JAN
ASP.NET MVC with Angular2 Development (online)

07:00 AM-09:00 AM IST(Tuesday & Thursday)

Know More
20 JAN
NODEJS & MEAN Stack 2 Development (online)

09:00 PM-11:00 PM IST( MON, WED, FRI)

Know More
15 JAN
PPC Marketing (offline)

04:00 PM-05:300 PM

14 JAN
Xamarin Forms : Build Cross-platform Apps (offline)

05:00 PM-06:30 PM IST

10 JAN
ASP.NET MVC with AngularJS Development (online)

09:00 PM-11:00 PM IST on (TUE, THRU,SAT)

3 JAN
ASP.NET MVC with AngularJS Development (online)

07:00 AM-09:00 AM IST

31 DEC
ASP.NET MVC with AngularJS Development (offline)

09:30 AM-11:00 AM

31 DEC
Angular2 and Angular1 Development (offline)

11:00 AM-12:30 AM

26 NOV
ASP.NET MVC with AngularJS Development (offline)

03:00 PM-04:30 PM

5 NOV
ASP.NET MVC with AngularJS Development (offline)

08:00 AM-09:30 AM

4 SEP
MEAN Stack 2 Development (offline)

11:00 AM-12:30 PM.

BROWSE BY CATEGORY
 
RECENT ARTICLES
SUBSCRIBE TO LATEST NEWS
 
LIKE US ON FACEBOOK
 

Professional Speaks

+