C# equivalent to db.repairDatabase()
Is there a way to call MongoDB's db.repairDatabase() function from the C# driver?
I am able to compact collections:
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:
The database.RunCommand method is overloaded. It can also take a string that is the name of command, as follows:
It also returns a CommandResult object.