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

MongoCollection.Count() method does not respect SlaveOk

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.3
    • Affects Version/s: 1.2
    • Component/s: None

      mongoDB Setup
      Replica Set with all secondaries, no primary is up.

      Sample Code:

      var server = MongoServer.Create(ConfigurationManager.AppSettings["connectionString"]);
      var db = server.GetDatabase("myDb", SafeMode.False);

      var settings = db.CreateCollectionSettings<Task>("Tasks");
      settings.SlaveOk = true;
      settings.SafeMode = SafeMode.False;

      var taskCollection = db.GetCollection(settings);

      var tasks = taskCollection.FindAll();

      var taskCount = taskCollection.Count();

      I can get the collection of items fine from taskCollection.FindAll(), but if I call taskCollection.Count(), driver throws the following error:

      MongoDB.Driver.MongoConnectionException: Unable to connect to the primary member of the replica set: No connection could be made because the target machine actively refused it

      Some troubleshooting leads me to believe the MongoCollection.Count() implementation is not respecting the SlaveOk setting.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            alanl Alan L.
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: