vedfi / mondroid

Mongodb Client w/ Flutter
GNU General Public License v3.0
63 stars 7 forks source link

Connect to db different from authSource? #43

Closed crunk1 closed 6 months ago

crunk1 commented 6 months ago

Hi there! I'm trying out your app and I'm running into an issue. I'm trying to connect to my Atlas cluster with the following connection string:

mongodb+srv://<my user>:<my pw>@cluster0.ocays.mongodb.net/bridge?authSource=admin&replicaSet=<my rs>&readPreference=primary&ssl=true

This connection string works in Compass. It does not work in your app. Note, the db name is bridge and authSource=admin. If I change bridge to admin, I can connect, but then I'm only seeing the admin db.

Also, a bit redundant information, but my user has the role dbAdminAnyDatabase@admin in Atlas.

Anything I'm doing wrong?

vedfi commented 6 months ago

Hello it seems like there is an authentication problem. Can you create a new user that has readWrite permission on bridge database. readWrite@bridge Then try to connect without readPreferences and ssl options. Then try both connection strings given below. mongodb+srv://<new-user>:<password>@cluster0.ocays.mongodb.net/bridge mongodb+srv://<new-user>:<password>@cluster0.ocays.mongodb.net/bridge?authSource=admin

Sometimes authentication method should be added to connection string like below. (SCRAM-SHA-1, SCRAM-SHA-256, MONGODB-CR). Also try both connection strings. mongodb+srv://<new-user>:<password>@cluster0.ocays.mongodb.net/bridge?authMechanism=SCRAM-SHA-1 mongodb+srv://<new-user>:<password>@cluster0.ocays.mongodb.net/bridge?authSource=admin&authMechanism=SCRAM-SHA-1

I will be waiting for your reply.

crunk1 commented 6 months ago

I was able to connect, thank you. Some notes:

I'm pretty sure I tried authMechanism before, but I didn't try authMechanism AND replicaSet at the same time.