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

Find operations should send read preference correctly when connected to a sharded cluster

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.2.3
    • Affects Version/s: 2.2
    • Component/s: Operations
    • Environment:
      Client: .Net Driver 2.2.2 on Windows 10 / .Net 4.6.1
      Server: 3.2.1 Shard on Debian

      Following example shows how to reproduce the Exception

      Command find failed: Failed to parse: { find: "bar", filter: {}, skip: 0, readPreference: { mode: "secondaryPreferred", tags: [ { dc: "ny", rack: "1" }, { dc: "sf" } ] }, noCursorTimeout: false, allowPartialResults: false }. Unrecognized field 'readPreference'..
      

      Driver from NuGet Package: (Legacy) Official C# driver for MongoDB 2.2.2

      var tagSets = new TagSet[]
      {
          new TagSet(new [] { new Tag("dc", "ny"), new Tag("rack", "1") }),
          new TagSet(new [] { new Tag("dc", "sf") })
      };
      
      MongoClientSettings clientSettings = new MongoClientSettings
      {
          Server = new MongoServerAddress("server"),
          ReadPreference = ReadPreference.SecondaryPreferred.With(tagSets)   <---- Exception
          //ReadPreference = ReadPreference.SecondaryPreferred   <----- Working
      };
      
      MongoClient client = new MongoClient(clientSettings);
      MongoServer server = client.GetServer();
      MongoDatabase database = server.GetDatabase("foo");
      MongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>("bar");
      
      MongoCursor<BsonDocument> cursor = collection.FindAll();
      
      foreach (BsonDocument bsonDocument in cursor)
      {
          Console.WriteLine(bsonDocument.ToString());
      }
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            mac866 Alice Mauschberger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: