The mongo shell is an interactive JavaScript shell for MongoDB, and is part of all MongoDB distributions.
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/