如何使用Node.js获取mongodb的从属状态? [英] How to get slave status of mongodb using nodejs?

查看:72
本文介绍了如何使用Node.js获取mongodb的从属状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用节点js获取mongodb服务器的slavestatus.这是代码.

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

但是我遇到了错误.

error = MongoError:没有这样的命令:'status',错误的cmd:'{status:1}'

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

推荐答案

那将是"replSetGetStatus"

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

})

如前所述,核心文档中有数据库命令的完整列表.这些是BSON结构的构建块",该结构被发送到服务器以启动操作.

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.

所有驱动程序实现中的所有内容都使用此命令列表.并且所有驱动程序都提供.command()的变体来发布它们.

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

这篇关于如何使用Node.js获取mongodb的从属状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆