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

Cannot pass 'writeConcern' to 'MongoClientOptions'

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • 4.7.0
    • 4.9.0
    • TypeScript
    • 2
    • Not Needed

    Description

      What problem are you facing?

      The API documentation of version 3.7 says the 'w' option is deprecated and asks users to use 'writeConcern' instead. However, instead of removing 'w' and keeping 'writeConcern' in version 4, the latest version accepts 'w' and rejects 'writeConcern', effectively asking users to switch back to the deprecated 'w' option.

      main.ts:8:7 - error TS2345: Argument of type '{ readConcern: { level: "majority"; }; writeConcern: { w: string; }; }' is not assignable to parameter of type 'MongoClientOptions'.
        Object literal may only specify known properties, and 'writeConcern' does not exist in type 'MongoClientOptions'.
       
      8       writeConcern: { w: 'majority' },
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
       
      Found 1 error in main.ts:8
      

       

      What driver and relevant dependency versions are you using?

      MongoDB Node.js Driver 4.7.0

      Steps to reproduce?

      Compile the code:
       

      import { MongoClient } from 'mongodb';
       
      async function run() {
        const client = new MongoClient(
          'mongodb://localhost',
          {
            readConcern: { level: 'majority' },
            writeConcern: { w: 'majority' },
          }
        );
       
        try {
          await client.connect();
       
          const database = client.db('test');
          const hellos = database.collection('hellos');
       
          const query = { name: 'abc' };
          const hello = await hellos.findOne(query);
       
          console.log(hello);
        } finally {
          await client.close();
        }
      }
      run().catch(console.dir);
      

      Attachments

        Issue Links

          Activity

            People

              neal.beeken@mongodb.com Neal Beeken
              tingweilan@noodoe.com 挺瑋 藍
              Daria Pardue
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: