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

Cannot pass 'writeConcern' to 'MongoClientOptions'

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.9.0
    • Affects Version/s: 4.7.0
    • Component/s: TypeScript
    • 2
    • Not Needed

      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:
       

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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);
      

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

              Created:
              Updated:
              Resolved: