I have recently created an account in mongoLab.When I am trying to connect to the database using the below statement.
var mongoose = require('mongoose');
mongoose.connect('mongodb://mk:[email protected]:47742/mkdb');
I'm always getting the following error
MongoError: auth failed
at Function.MongoError.create (/Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:793:66
at Callbacks.emit (/Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:94:3)
at null.messageHandler (/Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:235:23)
at Socket.<anonymous> (/Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:259:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
Make sure you are using the database username
and password
not the account username
and password
from Mlab.
In MLab, formerly MongoLab, do the following
Users
Add Database User
Now you can test this on the shell with
mongo ds061374.mlab.com:61374/yourdb -u <dbuser> -p <dbpassword>