Error on MongoClient.connect when connectWithNoPrimary is true and primary not set in url

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 2.2.22
    • Affects Version/s: 2.2.21
    • Component/s: None
    • Environment:
      ReplicaSet: PRIMARY+SEC x 2
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Code
      const URL = "mongodb://user:pass@sec1:27017,sec2:27017/db?replicaSet=rs";
      const OPTIONS = {
          "db": {
              "readPreference": "nearest",
              "bufferMaxEntries": 0
          },
          "replSet": {
              "replicaSet": "rs",
              "connectWithNoPrimary": true
          }
      };
      
      var MongoClient = require('mongodb').MongoClient;
      MongoClient.connect(URL, OPTIONS, function (err, db) {
          if (err) {
              console.log(err);
          } else {
              console.log("connect ok");
          }
      });
      

      If PRIMARY server is not added in URL and connectWithNoPrimary is true then a MongoError is thrown. Is PRIMAY is added or connectWithNoPrimary removed then MongoClient.connect is successful.

      Error
      MongoError: no connection available for operation and number of stored operation > 0
          at Function.MongoError.create (/data/test/node_modules/nimbus_mongo/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)
          at Store.add (/data/test/node_modules/nimbus_mongo/node_modules/mongodb/lib/topology_base.js:30:32)
          at ReplSet.auth (/data/test/node_modules/nimbus_mongo/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/replset.js:1099:37)
          at ReplSet.auth (/data/test/node_modules/nimbus_mongo/node_modules/mongodb/lib/replset.js:467:23)
          at authenticate (/data/test/node_modules/nimbus_mongo/node_modules/mongodb/lib/db.js:1519:21)
          at Db.authenticate (/data/test/node_modules/nimbus_mongo/node_modules/mongodb/lib/db.js:1557:44)
          at options (/data/test/node_modules/nimbus_mongo/node_modules/mongodb/lib/mongo_client.js:248:23)
          at /data/test/node_modules/nimbus_mongo/node_modules/mongodb/lib/db.js:236:5
          at ReplSet.connect.connectHandler (/data/test/node_modules/nimbus_mongo/node_modules/mongodb/lib/replset.js:339:7)
          at g (events.js:199:16)    
      

            Assignee:
            Christian Amor Kvalheim
            Reporter:
            Marius Ciocan
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: