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

Investigate NODE-4336 - Cannot pass 'writeConcern' to 'MongoClientOptions'

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • 1
    • Not Needed

      NODE-4336 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:
       

      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:
            bailey.pearson@mongodb.com Bailey Pearson
            Reporter:
            dbeng-pm-bot PM Bot
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: