What does authSource means in mongo database url?

前端 未结 2 1335
清酒与你
清酒与你 2021-01-01 19:21

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

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


        
2条回答
  •  借酒劲吻你
    2021-01-01 20:00

    I spent a few hours today trying to solve this problem and unfortunately, this SO post didn't appear in my searches. That was too bad because it's the post with the best answer to the problem.

    I hope to help the next person by adding the error message I got.

    I'm setting up the connection inside a Docker container that is spun up via a docker-compose yaml file. The user name and password are passed into docker-compose from a .env file.

    Connection URI that works

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

    Error:

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

提交回复
热议问题