-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: CLI Module, Documentation
-
None
-
Environment:MongoDB shell version v5.0.13
Ubuntu 20.04.5 LTS
-
Not Needed
Problem Statement/Rationale
I created a user on the database admin with role `readWriteAnyDatabase`, and I just wanna connect another database named users by using admin as the authentication database.
But I found that official docs say the path of connection URI is `defaultAuthDb`, but `mongo` command actually use it as the db to connect.
And `mongo --help` says it connects to the database specified by path.
$ mongo --help
MongoDB shell version v5.0.13
usage: mongo [options] [db address] [file names (ending in .js)]
db address can be:
foo foo database on local machine
192.168.0.5/foo foo database on 192.168.0.5 machine
192.168.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
mongodb://192.168.0.5:9999/foo connection string URI can also be used
Steps to Reproduce{}
1. Authenticated as root user to create a test user on database admin:
use admin db.createUser({ name: 'test-user', password: passwordPrompt(), roles: ['readWriteAnyDatabase'], })
2. Use the test user to connect to database users, and actual results:
# connected to database admin
$ mongo mongodb://test-user@hidden-info1.mongodb.rds.aliyuncs.com:3717,hidden-info2.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-62919502
- authentication failed, it meant mongosh used the URI path, named users, as the authentication database.
$ mongo mongodb://test-user@hidden-info1.mongodb.rds.aliyuncs.com:3717,hidden-info2.mongodb.rds.aliyuncs.com:3717/users?replicaSet=mgset-62919502
- connected to database users
$ mongo mongodb://test-user@hidden-info1.mongodb.rds.aliyuncs.com:3717,hidden-info2.mongodb.rds.aliyuncs.com:3717/users?replicaSet=mgset-62919502 --authenticationDatabase admin
# connected to database users
$ mongo "mongodb://test-user@hidden-info1.mongodb.rds.aliyuncs.com:3717,hidden-info2.mongodb.rds.aliyuncs.com:3717/users?replicaSet=mgset-62919502&authSoure=admin"
- connected to a database named test
$ mongo "mongodb://test-user@hidden-info1.mongodb.rds.aliyuncs.com:3717,hidden-info2.mongodb.rds.aliyuncs.com:3717/?replicaSet=mgset-62919502"
Expected Results
Above examples means that, the db name in path is actually always the connecting target db.
But the official web docs says it's `defaultAuthDb`, and there is nothing about the connecting target db in the docs.
So I expected the docs should say the db name in URI path is always the connecting target db, and then it will be used as default auth db if both `authSource` and `-authenticationDatabase` are unspecified.
Actual Results
Reference the section of Steps To Preproduce.