Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auth failed, code 18 when connecting to MongoLab database

I'm trying to connect to a MongoLab database but keep getting the following error on connection:

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

The code I'm using to connect is:

var mongoose = require("mongoose");

mongoose.connect("mongodb://username:[email protected]:61474/apitest");

mongoose.connection.on('error', function (err) {
    console.log(err);
});

When I connect using the shell, I have no problems whatsoever. What am I doing wrong?

like image 375
Jori Avatar asked Jan 04 '16 14:01

Jori


1 Answers

I faced the same issue while I try to import data from the locale to server.

Those 2 parameters can be important, it worked after I put them:

--authenticationMechanism 'MONGODB-CR' 
--authenticationDatabase "admin"

Be careful about the auth mechanism, can be a different one. Check this part of documentation: https://docs.mongodb.com/manual/reference/program/mongoimport/#cmdoption-mongoimport-authenticationmechanism

like image 95
Serdar D. Avatar answered Sep 21 '22 09:09

Serdar D.