[SERVER-33227] Using the method `connect` in a script will as a side effect update global `db`. Created: 09/Feb/18 Updated: 08/Jan/24 Resolved: 23/Feb/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | 3.4.0, 3.6.0, 3.7.2 |
| Fix Version/s: | 3.4.14, 3.6.4, 3.7.3 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Peter Ahlers | Assignee: | Kevin Pulo |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||
| Issue Links: |
|
||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||
| Operating System: | ALL | ||||||||||||
| Backport Requested: |
v3.6, v3.4
|
||||||||||||
| Steps To Reproduce: | Start two mongodbs (A and B). //psuedo-code Output will be something like Connection B {server:B} |
||||||||||||
| Sprint: | Sharding 2018-03-12 | ||||||||||||
| Participants: | |||||||||||||
| Description |
|
Using the method `connect` in a script will as a side effect update global `db` with the new connection. This is not how connect is described in the documentation https://docs.mongodb.com/manual/reference/method/connect/. The bug is introduced in version r3.3.12, in commit 88b540f0c14c7ab8af708aecc4cd6df83081b32e. On line 235 you see the connection is stored in `db`. Because the declaration of db is removed (old line 240) the new connection is stored in the global `db`. The global `db` is used for the connection where the script is running. |
| Comments |
| Comment by Peter Ahlers [ 26/Feb/18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Kevin Pulo, thanks for the script and fix. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 26/Feb/18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'email': 'kevin.pulo@mongodb.com', 'name': 'Kevin Pulo', 'username': 'devkev'}Message: (cherry picked from commit 1af47155814e1628b92597a58ed489b7509b6425) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 26/Feb/18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'email': 'kevin.pulo@mongodb.com', 'name': 'Kevin Pulo', 'username': 'devkev'}Message: (cherry picked from commit 1af47155814e1628b92597a58ed489b7509b6425) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 23/Feb/18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'email': 'kevin.pulo@mongodb.com', 'name': 'Kevin Pulo', 'username': 'devkev'}Message: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kevin Pulo [ 23/Feb/18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Peter, Thanks for letting us know about this! I can confirm that this is an unexpected regression in the behaviour of the connect() shell helper:
As expected, adding var in front of the definition of db fixes the problem:
I will now work on getting this fix committed and released. In the meantime, you can work around the problem by manually loading the above connect-fixed.js Best regards, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kelsey Schubert [ 12/Feb/18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi pahlers, Thanks for the clear bug report and investigative work – we're looking into it. Kind regards, |