3

I want to get slavestatus of mongodb server using node js. Here is the code.

var Db = require('mongodb').Db, Server = require('mongodb').Server;
        var db = new Db('admin', new Server(conf.host, conf.port));
        db.open(function(err, db1) {
            var adminDb = db1.admin();
             adminDb.command({ "status": 1 },function(err,result) {
                  console.log("output="+result);
            });
    });

But i am getting error.

error=MongoError: no such command: 'status', bad cmd: '{ status: 1 }'

4
  • Which operation are you trying to replicate? rs.status()? Commented May 20, 2017 at 6:31
  • You can probably save yourself a lot of trouble by taking the time to go through the complete list of Database Commands Commented May 20, 2017 at 6:49
  • Yes. rs.status() Commented May 20, 2017 at 7:13
  • Bad idea to ignore errors. Commented May 20, 2017 at 9:41

1 Answer 1

5

That would be "replSetGetStatus"

admiDb.command({ "replSetGetStatus": 1 }, function(err,result) {

})

As noted there is a full list of Database Commands in the core documentation. These are the "building blocks" of the BSON structure of what is sent to the server to initiate operations.

Just about everything in all driver implementations uses this command list. And all drivers provide a variant of .command() in order to issue them.

Sign up to request clarification or add additional context in comments.

1 Comment

@selvan That is the standard response if the server is not being run with that option. So your server is not a member of a replica set. You cannot get status from something that isn't in a replica set, therefore that is exactly the response you should receive. Start the server with the --repltSet option if you expect to see something different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.