Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-118

DropCollection fails with "not master" when SlaveOK is specified in connection string

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 0.9
    • 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

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            derfel J W Lee
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: