Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-33227

Using the method `connect` in a script will as a side effect update global `db`.

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 3.4.0, 3.6.0, 3.7.2
    • 3.4.14, 3.6.4, 3.7.3
    • Shell
    • None
    • Fully Compatible
    • ALL
    • v3.6, v3.4
    • Hide

      Start two mongodbs (A and B).

      //psuedo-code
      mongo A --eval="var connectionB = connect(B); print('Connection A', db); print('Connect B', connectionB)";

      Output will be something like
      Connection A

      {server:B}

      Connection B

      {server:B}
      Show
      Start two mongodbs (A and B). //psuedo-code mongo A --eval="var connectionB = connect(B); print('Connection A', db); print('Connect B', connectionB)"; Output will be something like Connection A {server:B} Connection B {server:B}
    • Sharding 2018-03-12

    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.

      Attachments

        1. connect-fixed.js
          2 kB
          Kevin Pulo

        Issue Links

          Activity

            People

              kevin.pulo@mongodb.com Kevin Pulo
              pahlers Peter Ahlers
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: