I can't seem to find a way of retrieving information on the database current operation using the mongodb module in Node.js.
I have tried something this:
mongodb = require 'mongodb'
server = new mongodb.Server 'localhost', 27017
connector = new mongodb.Db 'test', server
connector.open (err, db) ->
if not err?
db.admin().command {currentOp: 1}, (err, doc) ->
if not err?
console.log doc
of course without any result.
Does anybody have a pointer?
The way to do this directly from node mongodb native driver:
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://127.0.0.1:27017/', function (err, db) {
if (err) { throw err; }
db.collection('$cmd.sys.inprog').findOne(function (err, data) {
if (err) { throw err; }
console.log(data.inprog);
});
});
Although it's a command on the shell, it is not a real command. Instead, you need to query the $cmd.sys.inprog collection with findOne(). On the MongoDB shell, you would do:
db.$cmd.sys.inprog.findOne();
This seems to work, disregarding the MongoDB native driver for Node.js.
exec = require('child_process').exec
exec '/usr/bin/mongo --quiet --host="localhost:27017" "test" --eval "printjson(db.currentOp())"', (err, stdout) ->
console.error "#{err.message}" if err?
console.log JSON.parse stdout
Shouldn't this feature be implemented in the driver?