Introduction to MongoDB Mongo Shell

Rama Sagar
Posted by in NoSql category on for Beginner level | Points: 250 | Views : 6272 red flag
Rating: 4 out of 5  
 1 vote(s)

The mongo shell is an interactive JavaScript shell for MongoDB, and is part of all MongoDB distributions.
Recommendation
Read Introduction to MongoDB Replica set before this article.

Introduction

In this article we will learn about Mongo Shell we will see how to use this very important tool. If we going to use mongodb we use to spend lot of time in Mongo shell so if we know it better we can use it smartly….

Previous articles have provided an introduction to mongodb and the set up and installation,and few command line options.You can get them from the following:

Objective

The objective of the article is to learn about Mongo Shell in Mongo database.

We gonna discuss the role of the shell in the mongo echo system and explore some of the usage scenarios we gonna encounter…

We also gonna see some tips and tricks..

Shell and Mongo

 


As we know that our application is gonna talk to mongo server…..its gonna read write save data or whatever our application does……

But here lot of Questions arise

  • what exactly are they doing??
  • How is our mongo server feeling? Is it all configured right?
  • Is it performing well?
  • Does it save the data we want?
  • Does it have certain record?

 All these questions can be answered with the shell.

The Shell is simply an application that allows us to interactively get insight into what the mongo server is doing?

The shell uses the same wire protocol as our application would have. It’s simply another application that talks to mongod and is able to understand the wire protocol but it provides many capabilities..

Lets see some examples:

If we wanna rotate the log file we can provide the command

mongo localhost/admin --eval "db.runCommand({logRotate:1})"

 

we can notice a return of object object on screen if we wanna know what that thing  we can provide the command 

printjson (which prints the result of the command )

 we can wrap it around our orginal command

mongo localhost/admin --eval "printjson(db.runCommand({logRotate:1}))".


it was trying to tell us that everything is ok..

 Basic Keys



Conclusion

In this article we have learned about Mongo shell and how to make use of it and some basic keys.

Reference

http://docs.mongodb.org/manual/administration/scripting/

Page copy protected against web site content infringement by Copyscape

About the Author

Rama Sagar
Full Name: RamaSagar Pulidindi
Member Level: Silver
Member Status: Member,MVP
Member Since: 12/30/2012 1:51:40 AM
Country: India
ramasagar
http://www.ramasagar.com
A Software Profesional working in Microsoft .NET technologies since year 2008, and I work for Dake ACE. I am passionate about .NET technology and love to contribute to the .NET community at Dot Net Funda

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)