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

Make MongoClient.connect optional

    • Type: Icon: Epic Epic
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Native
    • None
    • Not Needed
    • Done
    • Get rid of MongoClient.connect

      Although we now conform to SDAM spec, we still diverge from other drivers in that we require an async call to MongoClient.prototype.connect before allowing operations on the client. This connect call involves many asynchronous actions like SRV resolution, instantiating connection pools, and initial server selection.

      Current flow:

      const client = new MongoClient('mongodb://localhost:27017');
      
      // This command will error b/c the client is not connected.
      await client.db('foo').collection('bar').insertOne({ a: 1 });
      
      // This is the proper workflow
      client.connect().then(async function() {
        await client.db('foo').collection('bar').insertOne({ a: 1 });
      });
      

      We'd like to eventually eliminate the need for this connect call so that all of the initial setup occurs as part of initial serverSelection.

            Assignee:
            Unassigned Unassigned
            Reporter:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: