What does authSource mean in mongo url?

I am trying to connect to my mongo database with the following connection string

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

I get an error like

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

Can anyone clear this "authSource = admin" thing for me.

+12
source share
2 answers

This is the name of the database in which there is a collection with user credentials.

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

Usernames and passwords are set here.

+10
source

, , , , . , .

, , .

Docker, yaml docker-compose. docker-compose .env.

URI ,

mongodb://aUser:aPassword@mevn-app-mongo:27017/myDb?authSource=admin

:

SASL SCRAM-SHA-1 authentication failed for aUser on myDb from client 172.25.0.3:37352 ; UserNotFound: Could not find user aUser@myDb
0

Source: https://habr.com/ru/post/1660777/


All Articles