Reputation: 1243
I am using node js as front end and mongodb is as backend. I got successfull connection. But while trying to get all the process running in mongodb are throw error. My code is below.
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.authenticate(conf.user, conf.password, function(err, result) {
if(result == true) {
var obj = adminDb.currentOp({"active":true});
console.log("output="+output);
}
});
});
I am getting below error.
TypeError: adminDb.currentOp is not a function
Upvotes: 1
Views: 1052
Reputation: 151112
You want .command()
:
adminDb.command({ "currentOp": 1, "active": true },function(err,result) {
// code in here
});
If you are ever looking for how things are "actually" executed, then go into the mongo shell and type the function without the ()
parentheses on the end. This will show you the definition.
I.E for currentOp()
:
> db.currentOp
function (arg) {
var q = {};
if (arg) {
if (typeof(arg) == "object")
Object.extend(q, arg);
else if (arg)
q["$all"] = true;
}
var commandObj = {"currentOp": 1};
Object.extend(commandObj, q);
var res = this.adminCommand(commandObj);
if (commandUnsupported(res)) {
// always send legacy currentOp with default (null) read preference (SERVER-17951)
var _readPref = this.getMongo().getReadPrefMode();
try {
this.getMongo().setReadPref(null);
res = this.getSiblingDB("admin").$cmd.sys.inprog.findOne(q);
} finally {
this.getMongo().setReadPref(_readPref);
}
}
return res;
}
Upvotes: 1