What does authSource means in mongo database url?

gaurav malik picture gaurav malik · Nov 15, 2016 · Viewed 22.2k times · Source

i am trying to connect to my mongo database with following connection string

var Mongo_url = 'mongodb://MyUSer:tech@localhost:27017/chatme?authSource=admin';  

I am getting error as

 assertionError: null == { [MongoError: Authentication failed.]
 name: 'MongoError',
 message: 'Authentication failed.',
 ok: 0,
 code: 18,

Could anyone please clear this "authSource=admin" thing to me.

Answer

Thilo picture Thilo · Nov 15, 2016

This is the name of the database that has the collection with the user credentials.

https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options

This is where the usernames and passwords are set up.