Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1581

"readPreference" option not honored on cursor.count()

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.1.1
    • Component/s: Native
    • Environment:
      Node v8.9.4
      Replica set: Primary, Secondary, Arbiter
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The following code will execute against the primary instead of the secondary:

      const url = 'mongodb://user:password@localhost:27018,localhost:27017/test?replicaSet=replset';
       MongoClient.connect(url, (err, client) => {
       const cursor = db.collection('test').find({});
       cursor.count(true,
      { readPreference: ReadPreference.SECONDARY }
      ).then(console.log);
       );
      
      

      It appears that the count function does not respect the read preference.

      Documentation: http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#count

      I have not tried to give the options to the find function, but setReadPreference works.

            Assignee:
            katherine.walker@mongodb.com Katherine Walker (Inactive)
            Reporter:
            bjarketrux Bjarke Pjedsted
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None