Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

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)

1 Answer

0 votes
by (108k points)

You have to make sure of the compatibility of the mongo shell to the mongodb version of the deployment. If you are deploying the database in MongoDB 3.4.x then your version should be in 3.4.x. The second thing is that the version of the driver you are using should also be the same as your MongoDB version of the deployment. For more information regarding the same, refer to the following link: https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/

Related questions

Browse Categories

...