[CSHARP-478] RunCommand("repairDatabase") throws an exception Created: 28/May/12  Updated: 02/Apr/15  Resolved: 06/Jun/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.4.2
Fix Version/s: 1.5

Type: Bug Priority: Major - P3
Reporter: Roman Kuzmin Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File Program.cs    

 Description   

The following command

database.RunCommand("repairDatabase")

throws the exception:

Message=Command 'repairDatabase' failed: bad option (response:

{ "errmsg" : "bad option", "ok" : 0.0 }

)
Source=MongoDB.Driver
StackTrace:
at MongoDB.Driver.MongoDatabase.RunCommandAs(Type commandResultType, IMongoCommand command) in C:\Active\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 981
at MongoDB.Driver.MongoDatabase.RunCommandAs(Type commandResultType, String commandName) in C:\Active\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 995
at MongoDB.Driver.MongoDatabase.RunCommandAs[TCommandResult](String commandName) in C:\Active\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 954
at MongoDB.Driver.MongoDatabase.RunCommand(String commandName) in C:\Active\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 930
at Program.Main(String[] args) in c:\ROM\DEV\TryMongo\Program.cs:line 16

Just a guess. If I use `1` instead of `true` in the C# driver code below then the command works.

MongoDatabase.RunCommandAs(Type commandResultType, string commandName)
Driver\Core\MongoDatabase.cs(994):

var command = new CommandDocument(commandName, true); // guess: perhaps `1` should be used, not `true`

At least, if we take a look at the definition of runCommand in the shell then we see that 1 is used:

> db.runCommand
function (obj) {
if (typeof obj == "string") {
var n = {};
n[obj] = 1;
obj = n;
}
return this.getCollection("$cmd").findOne(obj);
}

The full program code (very trivial) is attached.



 Comments   
Comment by Robert Stam [ 06/Jun/12 ]

Changed the default for commands to

{ commandName : 1 }

.

Comment by Robert Stam [ 29/May/12 ]

FYI, the Java driver uses true also instead of 1. There are very few commands that don't accept true.

Comment by Robert Stam [ 29/May/12 ]

Yes, it probably would.

Here's an easy workaround in the meantime:

var repairDatabaseCommand = new CommandDocument("repairDatabase", 1);
database.RunCommand(repairDatabaseCommand);

Comment by Roman Kuzmin [ 29/May/12 ]

I see. But the shell uses 1. It makes sense perhaps to use 1 in the driver as well.

Comment by Robert Stam [ 29/May/12 ]

Thanks for reporting this. The server normally accepts either 1 or true as the value of command names, but every now and then a command is picky and refuses one or the other.

Generated at Wed Feb 07 21:36:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.