Getting the Status of the MongoDB Server

Another great feature of the Admin object is the ability to get status information about the MongoDB server. This information includes the hostname, version, uptime, open cursors, and much more. You can use this information to determine the health and status of the MongoDB server and then make adjustments in your code to handle problem situations.

To display the status of the MongoDB server, you use the serverStatus() method on the Admin object. Listing 13.4 illustrates how to create the Admin object and then call serverStatus(). Figure 13.4 shows the results of Listing 13.4.

Listing 13.4 db_status.js: Retrieving and displaying the MongoDB server status


1 var MongoClient = require('mongodb').MongoClient;
2 MongoClient.connect("mongodb://localhost/test", function(err, db) {
3   var adminDB = db.admin();
4   adminDB.serverStatus(function(err, status){
5     console.log(status);
6     db.close();
7   });
8 });


Image

Figure 13.4 Retrieving and displaying the MongoDB server status.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset