[MongoError: auth failed] when connecting to database

1,305 views
Skip to first unread message

Henry Spindell

unread,
Oct 9, 2015, 5:44:35 AM10/9/15
to mongodb-user

My Node application recently started returning the following error when connecting to the database. It has connected successfully for over 2 years up until now, and I have not changed the connection code or the user credentials.


connection error: { [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 }


Here is my connection code:

var db = mongoose.createConnection(' mongodb://admin:<adminpassword>@ds063869.mongolab.com:63869/<dbname>');


I'm using mongoose 3.8.4, mongo 3.0.6 and node 0.10.33. I didn't see anyone else with this problem, so if anyone has ideas I'd really appreciate it. Thanks!

Santosh Wadghule

unread,
Oct 9, 2015, 4:24:00 PM10/9/15
to mongodb-user
I'm also facing same issue. For last more than 1 year my nodejs app was working fine. But suddenly from 1 week, I'm getting same error.

It happens only through when I access database through URI string. From shell it works fine.

Stephen Steneker

unread,
Oct 11, 2015, 8:25:05 PM10/11/15
to mongodb-user
Hi Henry, Santosh,

What version of the MongoDB node driver are you using ? MongoLab recently updated to MongoDB 3.0, so if you haven't updated your application in more than a year I suspect you need to upgrade your driver to a version that is fully compatible: http://docs.mongodb.org/ecosystem/drivers/driver-compatibility-reference/#reference-compatibility-mongodb-node.

For more information on MongoLab versions see: http://docs.mongolab.com/db-version-requirements/.

Regards,
Stephen

Henry Spindell

unread,
Oct 17, 2015, 6:30:46 PM10/17/15
to mongodb-user
Hi Stephen,

Thanks for the reply. I was on 3.0.6, just updated to 3.0.7 and am getting the same issue. Like Santosh, I am still able to access through shell.

Stephen Steneker

unread,
Oct 17, 2015, 6:43:28 PM10/17/15
to mongodb-user
On Sunday, 18 October 2015 09:30:46 UTC+11, Henry Spindell wrote:
Thanks for the reply. I was on 3.0.6, just updated to 3.0.7 and am getting the same issue. Like Santosh, I am still able to access through shell.

Hi Henry,

As I mentioned earlier, the issue is likely due to your Node.js driver requiring an update for MongoDB 3.0.x support:

You will need 1.4.29 or newer of the Node.js driver; I would try upgrading to the latest 1.4.x driver (currently 1.4.39).

The current Node driver release series is 2.0.x, but will likely require some changes to application code to update from the older API:

Regards,
Stephen

Henry Spindell

unread,
Oct 17, 2015, 7:03:55 PM10/17/15
to mongodb-user
Ah, I misunderstood. Updated my package.json to use "mongodb": "^1.4.39" and it's connecting successfully. Thanks a bunch, I really appreciate your quick response!
Reply all
Reply to author
Forward
0 new messages