Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2234

isConnected() takes legacy path with useUnifiedTopology

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.4
    • Affects Version/s: 3.3.2
    • Component/s: MongoDB 3.2
    • Environment:
      Not using Mongoose. Not transpiling the driver.

      Using the Node Driver, I create a connection with the "useUnifiedTopology" option set to true with a snippet like this.

        const { url } = databaseConfig;  
        const databaseConnection = new MongoClient(url, {
           useUnifiedTopology: true,
           useNewUrlParser: true,
         });
         return databaseConnection.connect();
      

       

      Later I close the connection and check to see if it's closed:

      await client.close();
      expect(client.isConnected()).toBe(false); // this fails because it's true

      When tracing the isConnected() call it ends up returning true (always) from here:

      https://github.com/mongodb/node-mongodb-native/blob/dc70c2de7d3dae2617708c45a1ea695d131e15f3/lib/core/sdam/topology.js#L663

      If I change the useUnifiedTopology to false and leave everything else the same then the code works as expected and this line is hit instead:

      https://github.com/mongodb/node-mongodb-native/blob/dc70c2de7d3dae2617708c45a1ea695d131e15f3/lib/topologies/topology_base.js#L340

       

       

       

       

       

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            wildfiction@gmail.com Guy Ellis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: