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

Pick best format for boilerplate connect code

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Docs
    • None

      Currently, we have two suggestions:

      const { MongoClient } = require('mongodb');
      const assert = require('assert');
      
      // Connection URL
      const url = 'mongodb://localhost:27017';
      
      // Database Name
      const dbName = 'myproject';
      
      // Create a new MongoClient
      const client = new MongoClient(url);
      
      async function main() {
        // Use connect method to connect to the Server
        await client.connect();
        
        try {
          // content here
        } finally {
          await client.close();
        }
      }
      
      main().catch(console.dir);
      
      const { MongoClient } = require('mongodb');
      const assert = require('assert');
      
      // Connection URL
      const url = 'mongodb://localhost:27017';
      
      // Database Name
      const dbName = 'myproject';
      
      // Create a new MongoClient
      const client = new MongoClient(url);
      
      // Use connect method to connect to the Server
      client.connect().then(async function() {
        try {
          // content here
        } finally {
          await client.close();
        }
      });
      

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

              Created:
              Updated:
              Resolved: