MongoDB tools

In previous section, we have discuss about some commands and operations related to MongoDB. This section will explain you about the MongoDB tools and what are are the use of those tools.

MongoDB installation contains all the following commands are available. There are certain tools which are exist in the Mongo DB database. Some of them are:


Among all MongoDB tools, mongo shell is an interactive java Script shell for Mongo DB, which lets developers view, insert, remove and update data in their database: as well as get replication information, setup sharding shutdown servers,  execute JavaScript and more. Administrative information can also be accessed through a web interface, a simple web page that servers information about the current server status. By default, this interface is 1000 ports above the database port (28017).


Mongotop is a command line tool providing a method to track the amount of time a Mongo DB instance spends reading and writing data. By default Mongo DB returns values in every second. mongotop returns the time value  in the millisecond. Mongotop only reports active databases, depending on the –lock option. If we do not see a collection or database, it has received no recent activity. The following snapshot is showing how the mongotop is working.


Mongostat is a tool which is basically known as command line tool that displays a summary list of status statistics for a current running Mongo DB instance, how many inserts, updates, removes, queries, and commands were performed as well as what percentage of the time the database was locked and how much memory it is using. That means it allows you to view overview about your database server in real time.

If you are running mongod locally on its standard 27017 port then you can just start mongostat and it will automatically connect. Otherwise, you can specify one or many hostnames + ports to connect to. The screenshot above shows all the servers in our Mongo DB cluster.

There are some data which is shown after executing the mongostat command. Some of the examples are:


This shows how many times data has been flushed to disk. Mongo DB Only physically writes data to disk every 60 seconds (by default). This has the effect of increasing performance but can decrease durability because a hard crash in between flushes will result in that data not being written, and therefore lost. v1.8 solves this with the option for durability but this stat shows how often mongod is flushing data to disk.


The faults column shows you the number of Linux page faults per second. This is when Mongo accesses something that is mapped to the virtual address space but not in physical memory. i.e. it results in a read from disk. High values here indicate  you may not have enough RAM to store all necessary data and disk accesses may start to become the bottleneck.

locked %

Shows the % of time in a global write lock. When this is happening no other queries will complete until the lock is given up, or the lock owner yields. This is indicative of a large, global operation like a remove() or dropping a collection and can result in slow performance.

% idx miss

% idx miss is like we saw in the server status output except instead of an aggregate total, you can see queries hitting (or missing) the index in real time. This is useful if you are debugging specific queries in development or need to track down a server that is performing badly.


When MongoDB gets too many queries to handle in real time, it queues them up.

This is represented in mongostat by the read and write queue columns. When this starts to increase you will see slowdowns in executing queries as they must wait to run through the queue. You can alleviate this by stopping any more queries until the queue has dissipated. Queues will tend to spike if you’re doing a lot of write operations alongside other write heavy ops, such as large ranged removes.

mongostat” is useful because it shows what is happening in your cluster right now. This is particularly handy to quickly find out which member of your replica sets is master right now – the final column shows this. If you start seeing slowdowns or suspect a problem with Mongo DB, mongostat should be your first point of call to quickly locate where the problem is.


Generally sniffing means tracing. So mongosniff is a command line tool which provides a low level tracing or sniffing view into database activity by monitoring or sniffing network traffic going to and from mongo DB. mongosniff requires the Libpcap network library using and is only available for Linux based system. A cross- platform alternative is open source wire shark packet analyzer which has full support for the mongo DB wire protocol.

Mongodump and mongorestore:

Mongodump is a command line utility for creating a binary export of the contents of a mongo database. Mongorestore can be used reload a database dump. The important point is mongodump does not create output for the local database. Mongodump can read Data from mongod or mongos instances, in addition to reading directly from Mongo DB data files without an active mongod. The main behaviors of mongorestore are mongostore recreates indexes recorded by mongodump. In this case all operations should be insert but not update. Another use of mongorestore is it does not wait for a response from mongod to ensure that the Mongo DB process has received or recorded the operations.

Mongodump example :

Mongorestore example:

In this section, we have discussed about the MongoDB tools and use of all those tools. In next section we will discuss about some example how to implement MongoDB in Java. Also we will see how all these MongoDB tools are used this example.

Leave a Reply

Your email address will not be published. Required fields are marked *