Details
Description
When I try to connect using read preference and read preference tags via the Mongo shell v4.0.0, it doesn't behave as I would expect given current documentation. For example, the docs say:
However, when I try to connect and execute the following command.js script:
db.getSiblingDB("test").foo.find()
|
I get the following behavior (removed some replication logs for brevity):
The script:
mongo "mongodb+srv://db.example.com/test?readPreferenceTags=location:US" --username username --password password < command.js
|
mongo "mongodb+srv://db.example.com/test?readPreference=secondary&readPreferenceTags=location:US" --username username --password password < command.js
|
mongo "mongodb+srv://db.example.com/test?readPreference=secondary&readPreferenceTags=location:CA" --username username --password password < command.js
|
mongo "mongodb+srv://db.example.com/test?readPreference=secondary&readPreferenceTags=location:RS" --username username --password password < command.js
|
The output (minus unnecessary log lines):
MongoDB shell version v4.0.0
|
connecting to: mongodb+srv://db.example.com/test?readPreferenceTags=location:US
|
MongoDB server version: 4.0.0
|
{ "_id" : ObjectId("5c3fcdc67ffe2f5b036bdd98"), "a" : 1 }
|
bye
|
MongoDB shell version v4.0.0
|
connecting to: mongodb+srv://db.example.com/test?readPreference=secondary&readPreferenceTags=location:US
|
MongoDB server version: 4.0.0
|
{ "_id" : ObjectId("5c3fcdc67ffe2f5b036bdd98"), "a" : 1 }
|
bye
|
MongoDB shell version v4.0.0
|
connecting to: mongodb+srv://db.example.com/test?readPreference=secondary&readPreferenceTags=location:CA
|
MongoDB server version: 4.0.0
|
{ "_id" : ObjectId("5c3fcdc67ffe2f5b036bdd98"), "a" : 1 }
|
bye
|
MongoDB shell version v4.0.0
|
connecting to: mongodb+srv://db.example.com/test?readPreference=secondary&readPreferenceTags=location:RS
|
MongoDB server version: 4.0.0
|
{ "_id" : ObjectId("5c3fcdc67ffe2f5b036bdd98"), "a" : 1 }
|
bye
|
The same output occurs for the non-SRV connection string, e.g.
mongo "mongodb://db-0.example.com:27017,db-1.example.com:27017,db-2.example.com:27017/test?replicaSet=db-0&readPreferenceTags=location:US" --ssl --authenticationDatabase admin --username username --password password < command.js
|
mongo "mongodb://db-0.example.com:27017,db-1.example.com:27017,db-2.example.com:27017/test?replicaSet=db-0&readPreference=secondary&readPreferenceTags=location:US" --ssl --authenticationDatabase admin --username username --password password < command.js
|
mongo "mongodb://db-0.example.com:27017,db-1.example.com:27017,db-2.example.com:27017/test?replicaSet=db-0&readPreference=secondary&readPreferenceTags=location:CA" --ssl --authenticationDatabase admin --username username --password password < command.js
|
mongo "mongodb://db-0.example.com:27017,db-1.example.com:27017,db-2.example.com:27017/test?replicaSet=db-0&readPreference=secondary&readPreferenceTags=location:RS" --ssl --authenticationDatabase admin --username username --password password < command.js
|
When I connect manually using one of those connection strings, and I run db.getMongo().getReadPrefMode() and db.getMongo().getReadPrefTagSet(), both returned nothing, leading me to believe the shell is not properly parsing the connection string parameters.
Given that we have functions inside of the shell to manually specify the read preference, it would be nice if the mongo shell could instead parse the readPreference and readPreferenceTags mongo URI options if specified.
Attachments
Issue Links
- is related to
-
SERVER-48769 Shell does not respect read preference in connection string
-
- Closed
-
- mentioned in
-
Page Loading...