Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running db.repairDatabase() from mongodb-native in node.js

I can run db.repairDatabase() from the mongodb shell but I can't find an example on running the same command from node.js app using the mongodb-native module. How can I run "repairDatabase" with executeDbCommand method?

like image 730
strada Avatar asked Feb 19 '12 22:02

strada


People also ask

How do I get data from MongoDB collection using node JS?

To select data from a collection in MongoDB, we can use the findOne() method. The findOne() method returns the first occurrence in the selection. The first parameter of the findOne() method is a query object.


2 Answers

db.command({repairDatabase:1}, function(err, result) {

});
like image 166
christkv Avatar answered Sep 21 '22 23:09

christkv


If you want to see what the mongo javascript shell does, just remove the parenthesis and it will show you the underlying code:

> db.repairDatabase
function () {
    return this._dbCommand({repairDatabase:1});
}
//This basically...
>return this.getCollection("$cmd").findOne({repairDatabase:1});

See this code in the driver for the implementation.

like image 35
Scott Hernandez Avatar answered Sep 18 '22 23:09

Scott Hernandez