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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 0.9
    • 0.7
    • None
    • None
    • N/A
    • Fully Compatible

    Description

      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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: