-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 0.7
-
Component/s: None
-
None
-
Environment:N/A
-
Fully Compatible
When SlaveOk is specified in the connection string, the DropCollection command fails as the driver uses the generic FindOneAs() function to send the command to mongodb. FindOneAs() will pick a slave as it thinks it is a read operation and SlaveOk has been set.
Steps to reproduce:
1) Create a mongodb replica set with at least one master and one slave
2) Use a connection string that specifies SlaveOk
3) Execute DropCollection on a database
4) "Not master" exception is thrown
Callstack (line numbers may be incorrect):
> MongoDB.Driver.dll!MongoDB.Driver.MongoDatabase.RunCommandAs<MongoDB.Bson.BsonDocument,MongoDB.Driver.CommandResult>(MongoDB.Bson.BsonDocument command) Line 343 C#
MongoDB.Driver.dll!MongoDB.Driver.MongoDatabase.RunCommand<MongoDB.Bson.BsonDocument>(MongoDB.Bson.BsonDocument command) Line 319 + 0x30 bytes C#
MongoDB.Driver.dll!MongoDB.Driver.MongoDatabase.DropCollection(string collectionName) Line 178 + 0x10 bytes C#
Root cause:
var result = CommandCollection.FindOneAs<TCommand, TCommandResult>(command); // this will cause a slave to be chosen as the connection