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?
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.
db.command({repairDatabase:1}, function(err, result) {
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With