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

Querying replica set without primary in Strict mode gives TypeError

      Given:

      • A mongodb replica set that has no primary (e.g. the majority went down)
      • Node client with Replica set connection (replicaSet=rs0)
      • Node client options: readPreference: ReadPreference.NEAREST, connectWithNoPrimary: true

      Then I expect that I can execute query operations like db.collection() and find(). Also I want to use the collection() strict mode in orde to determine if a collection is empty or does not exist.

      Behaviour:

      • db.collection(strict: true) gives:
        Collection error:  TypeError: Cannot read property 'command' of undefined
            at nextFunction (/nfs/home/hidden/DataCollecties/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:568:51)
            at Cursor.next [as _next] (/nfs/home/hidden/DataCollecties/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:692:3)
            at fetchDocs (/nfs/home/hidden/DataCollecties/node_modules/mongodb/lib/cursor.js:856:10)
            at toArray (/nfs/home/hidden/DataCollecties/node_modules/mongodb/lib/cursor.js:883:3)
            at Cursor.toArray (/nfs/home/hidden/DataCollecties/node_modules/mongodb/lib/cursor.js:836:44)
            at Db.collection (/nfs/home/hidden/DataCollecties/node_modules/mongodb/lib/db.js:473:37)
            at /nfs/home/hidden/DataCollecties/testquerynoprimary.js:14:8
            at connectCallback (/nfs/home/hidden/DataCollecties/node_modules/mongodb/lib/mongo_client.js:428:5)
            at /nfs/home/hidden/DataCollecties/node_modules/mongodb/lib/mongo_client.js:347:11
            at nextTickCallbackWith0Args (node.js:419:9)
        

      Sample nodejs program attached.
      Usage:

      1. Prepare 2 mongod processes, running on ports 29000 and 29001.
      2. Initiate a replication set "rs0"
      3. Kill one of the mongod processes, effectively making the remaining instance a Secondary.
      4. Run testquerynoprimary.js as given below:
      $ set MONGO_CONNECTION_STRING=mongodb://localhost:29000,localhost:29001/myDb?replicaSet=rs0
      
      $ MONGO_STRICT=false node testquerynoprimary.js
      Using: mongodb://localhost:29000,localhost:29001/myDb?replicaSet=rs0 false
      Find OK: size:  0
      
      $ MONGO_STRICT=true node testquerynoprimary.js
      Using: mongodb://localhost:29000,localhost:29001/myDb?replicaSet=rs0 true
      Collection error:  .... etc ....
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            wverheijen Wouter Verhejien
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: