Is there a way to call MongoDB's db.repairDatabase() function from the C# driver?
I am able to compact collections:
database.RunCommand(new CommandDocument("compact","collectionname"));
But I don't manage to call repairDatabase.
In response to your comment that you got an exception with the message "bad option", it turns out that the server is picky about whether you use 1 or true as the value for the repairDatabase field. The following two are equivalent and both fail because the server doesn't like "true" instead of "1":
database.RunCommand("repairDatabase");
database.RunCommnad(new CommandDocument("repairDatabase", true));
but this works:
database.RunCommnad(new CommandDocument("repairDatabase", 1));
You could report a JIRA against the server if this concerns you:
https://jira.mongodb.org/browse/SERVER
The database.RunCommand method is overloaded. It can also take a string that is the name of command, as follows:
database.RunCommand("repairDatabase")
It also returns a CommandResult object.
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