1
dburl = "mongodb://127.0.0.1:27017/demo";
db = require('mongojs').connect(dburl);
console.log(db.version);

I want to know mongodb version using mongojs.

1 Answers1

3

Try this:

db.executeDbCommand({ buildInfo : 1 }, function(err, buildinfo) {
  console.log('V', buildinfo.documents[0].version);
});

EDIT: shorter version using command():

db.command({ buildInfo : 1 }, function(err, buildinfo) {
  console.log('V', buildinfo.version);
});

To get a list of commands that you can execute:

db.command({ listCommands : 1 }, function(err, response) {
  console.log(response.commands);
});
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • Thanks Robert, it is working fine. Can you let me know from where can i get db.executeDbCommand tutorials ? – Rohit Jindal Jun 05 '13 at 06:58
  • @RohitJindal I think `executeDbCommand` is deprecated, I edited my answer to show an alternative and also a way of listing all available commands. – robertklep Jun 05 '13 at 07:40