[CSHARP-1537] Find operations should send read preference correctly when connected to a sharded cluster Created: 19/Jan/16  Updated: 02/Apr/16  Resolved: 20/Jan/16

Status: Closed
Project: C# Driver
Component/s: Operations
Affects Version/s: 2.2
Fix Version/s: 2.2.3

Type: Bug Priority: Critical - P2
Reporter: Alice Mauschberger Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Client: .Net Driver 2.2.2 on Windows 10 / .Net 4.6.1
Server: 3.2.1 Shard on Debian



 Description   

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());
}



 Comments   
Comment by Robert Stam [ 21/Jan/16 ]

The following two commits were also for CSHARP-1537, but unfortunately the commit message had two digits of the ticket number transposed so the github hook didn't automatically create messages for them in this ticket:

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1357: Find operations should send read preference correctly when connected to a sharded cluster.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/d56b690c024980690fc4efe68cdbd00a6d07ccb6

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1357: Find operations should send read preference correctly when connected to a sharded cluster.
Branch: v2.2.x
https://github.com/mongodb/mongo-csharp-driver/commit/bdbfec2f1d044b5265318797442641e473be1ee1

Comment by Githook User [ 21/Jan/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1537: Added tests for CommandOperationBase, ReadCommandOperation and WriteCommandOperation.
Branch: v2.2.x
https://github.com/mongodb/mongo-csharp-driver/commit/464b927f4a7cff9eb9818d8ed078e3d4adc77fb0

Comment by Githook User [ 21/Jan/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1537: Added tests for CommandOperationBase, ReadCommandOperation and WriteCommandOperation.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/c4c3233b5d2e045223276df637d9d4f8ac412b51

Comment by Robert Stam [ 19/Jan/16 ]

Thanks for reporting this. We're going to give fixing this high priority.

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