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.
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 });