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

"MongoError: auth failed" when using proper MongoClient connect string

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

      I'm getting the following error when attempting to connect to my mongo replset which has auth protection (just created a simple admin user and specifying a keyFile):

      code
      /Users/montgomeryc/Projects/mongoskin-auth-test/node_modules/mongodb/lib/mongodb/mongo_client.js:460
      throw err
      ^
      MongoError: auth failed
      at Object.toError (/Users/montgomeryc/Projects/mongoskin-auth-test/node_modules/mongodb/lib/mongodb/utils.js:114:11)
      at /Users/montgomeryc/Projects/mongoskin-auth-test/node_modules/mongodb/lib/mongodb/db.js:1131:31
      at /Users/montgomeryc/Projects/mongoskin-auth-test/node_modules/mongodb/lib/mongodb/db.js:1846:9
      at Server.Base._callHandler (/Users/montgomeryc/Projects/mongoskin-auth-test/node_modules/mongodb/lib/mongodb/connection/base.js:445:41)
      at /Users/montgomeryc/Projects/mongoskin-auth-test/node_modules/mongodb/lib/mongodb/connection/server.js:478:18
      at MongoReply.parseBody (/Users/montgomeryc/Projects/mongoskin-auth-test/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
      at null.<anonymous> (/Users/montgomeryc/Projects/mongoskin-auth-test/node_modules/mongodb/lib/mongodb/connection/server.js:436:20)
      at EventEmitter.emit (events.js:95:17)
      at null.<anonymous> (/Users/montgomeryc/Projects/mongoskin-auth-test/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:201:13)
      at EventEmitter.emit (events.js:98:17)
      code

      I have a very simple node app that reproduces this error:

      code
      var MongoClient = require('mongodb').MongoClient;
      var url = "mongodb://admin:password@localhost:27017,localhost:27018,localhost:27019/tesla-wsj";
      MongoClient.connect(url, function (err, db) {
      if (err) throw err;
      console.log("connect and auth success!!");
      });
      code

      I'm following the URL connection format listed here: http://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html#the-url-connection-format

      What's strange is, if I specify the auth for each mongo in the replset, it succeeds. e.g.:

      code
      "mongodb://admin:password@localhost:27017,admin:password@localhost:27018,admin:password@localhost:27019/tesla-wsj"
      code

      Why does it work for the second string and not the first? do I possibly have a misconfigured replset? For reference, here's my rs.status():

      code
      wsj_app:PRIMARY> rs.status()
      {
      "set" : "wsj_app",
      "date" : ISODate("2014-06-06T15:55:48Z"),
      "myState" : 1,
      "members" : [

      { "_id" : 1, "name" : "localhost:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 67243, "optime" : Timestamp(1402002612, 1), "optimeDate" : ISODate("2014-06-05T21:10:12Z"), "electionTime" : Timestamp(1402002932, 1), "electionDate" : ISODate("2014-06-05T21:15:32Z"), "self" : true }

      ,

      { "_id" : 2, "name" : "localhost:27018", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 67222, "optime" : Timestamp(1402002612, 1), "optimeDate" : ISODate("2014-06-05T21:10:12Z"), "lastHeartbeat" : ISODate("2014-06-06T15:55:48Z"), "lastHeartbeatRecv" : ISODate("2014-06-06T15:55:48Z"), "pingMs" : 0, "syncingTo" : "localhost:27017" }

      ,

      { "_id" : 3, "name" : "localhost:27019", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 67209, "optime" : Timestamp(1402002612, 1), "optimeDate" : ISODate("2014-06-05T21:10:12Z"), "lastHeartbeat" : ISODate("2014-06-06T15:55:48Z"), "lastHeartbeatRecv" : ISODate("2014-06-06T15:55:48Z"), "pingMs" : 0, "syncingTo" : "localhost:27017" }

      ],
      "ok" : 1
      }
      code

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            cmontgomery Chris Montgomery
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: