[CSHARP-463] Unexpected and not documented exception in MongoDatabase.CreateCollection(String, IMongoCollectionOptions) Created: 03/May/12  Updated: 02/Apr/15  Resolved: 11/Jun/12

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

Type: Improvement Priority: Minor - P4
Reporter: Roman Kuzmin Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-474 Review all exceptions thrown by the C... Closed

 Description   

I am trying to create a collection which already exists (a capped one, if this
matters). As far as the method returns `CommandResult`, I expect it to return
an error information (and I write ahead some code that check for `Ok` and uses
the error message). But instead the method throws an exception.

I propose either to document this exception (it is not) or, better, to not
throw but return an error. The latter is more expected and consistent with,
say, `DropCollection` which does not throw on missing collections but returns
error information.



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

The general rule with all commands is that the driver throws an exception when the server returns

{ ok : 0 }

as part of the result of the command.

CreateCollection follows this rule to the letter. DropCollection follows it with one exception: if the server returns

{ ok : 0 }

with an error message of "ns not found" the error is considered benign and ignored. All the drivers do this. Really the server should not be returning an error in this case, but apparently the server is not going to be changed.

You don't need to check the OK property of a CommandResult. If no exception was thrown the command succeeded.

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