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

Pick best format for boilerplate connect code

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Docs
    • None

    Description

      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();
        }
      });
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: