[SERVER-48769] Shell does not respect read preference in connection string Created: 11/Jun/20 Updated: 27/Oct/23 Resolved: 31/Jan/23 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | 4.4.0-rc9 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Siyuan Zhou | Assignee: | Backlog - Server Tooling and Methods (STM) (Inactive) |
| Resolution: | Gone away | Votes: | 1 |
| Labels: | move-stm | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||
| Assigned Teams: |
Server Tooling & Methods
|
||||||||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||||||||
| Steps To Reproduce: | In on terminal, start a replset with 3 nodes.
In another terminal, start a mongo shell with read preference secondary in the URI. The prompt shows it connects to the primary.
|
||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||
| Description |
|
As described in the steps to reproduce, the shell failed to connect to a secondary even though the connection string specifies read preference "secondary" according to the documentation. URI option support isn't consistent and user-friendly in the shell. Some URI options are supported. For example a wrong "replicaSet" option will be detected as it fails to connect. However read preference is ignored silently. Initially I thought my options were wrong or read preference has to be given together with "replicaSet" or the database was misconfigured when I tried to connect the data warehouse not owned by my team. Misspelling an option is also a silent error. For example, "replSet" option will be ignored silently. The shell seems the easiest way to try out read preferences settings, so I feel the lack of support is a bug. As least, the unsupported or unknown URI options should be an explicit error. |
| Comments |
| Comment by Chris Harris [ 31/Jan/23 ] | |||||
|
This ticket was opened against the legacy mongo shell which has since been deprecated and removed. The newer MongoDB Shell (mongosh) accepts and respects all configurations in a connection string. | |||||
| Comment by Steven Vannelli [ 10/May/22 ] | |||||
|
Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions. | |||||
| Comment by Dmitry Ryabtsev [ 05/Jan/21 ] | |||||
|
This appears to be a duplicate of | |||||
| Comment by Max Hirschhorn [ 12/Jun/20 ] | |||||
|
Setting the read preference on a Mongo connection object must currently be done through Mongo.prototype.setReadPref(). It doesn't automatically get filled in based on the connection string.
I think it is worth clarifying that setting a "secondary" read preference at a connection string level isn't meant to cause all commands to be routed to a secondary. The mongo shell only attaches the read preference when DB.prototype.runReadCommand() is used. The read preference will also be ignored if the command isn't part of this list.
According to the driver's specification, the mongo shell ought to be logging a warning about unknown options. |