Pick best format for boilerplate connect code

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Docs
    • None
    • None
    • None
    • None
    • None
    • None
    • 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 (Inactive)
              Reporter:
              Daniel Aprahamian (Inactive)
              None
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: