Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-14149

writeConcern w:0 with j:true doesn't work

      Description

      Hi Team,

      As per our documentation in writeConcern,

      If you specify w: 0 but include j: true, the j: true prevails to request acknowledgment from the standalone mongod or the primary of a replica set.
      

      This is not allowed through any driver connectivity, because of java-driver, PyMongo throws error like below:
      //java

       ?minPoolSize=15&maxPoolSize=45&connectTimeoutMS=30000&socketTimeoutMS=60000&wtimeoutMS=300&retryWrites=true&ssl=false&authMechanism=SCRAM-SHA-1&w=0&journal=true 
      
      java.lang.IllegalArgumentException: state should be: journal is false when w is 0 
      

      //Pymongo

      >>> uri="mongodb://root:rootpass@127.0.0.1:27017/admin?authMechanism=SCRAM-SHA-1&w=0&journal=true"
      >>> 
      >>> 
      >>> conn = mc(uri)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/darshanj/anaconda3/lib/python3.7/site-packages/pymongo/mongo_client.py", line 692, in __init__
          username, password, dbase, opts)
        File "/Users/darshanj/anaconda3/lib/python3.7/site-packages/pymongo/client_options.py", line 164, in __init__
          self.__write_concern = _parse_write_concern(options)
        File "/Users/darshanj/anaconda3/lib/python3.7/site-packages/pymongo/client_options.py", line 61, in _parse_write_concern
          return WriteConcern(concern, wtimeout, j, fsync)
        File "/Users/darshanj/anaconda3/lib/python3.7/site-packages/pymongo/write_concern.py", line 76, in __init__
          raise ConfigurationError("Cannot set w to 0 and j to True")
      pymongo.errors.ConfigurationError: Cannot set w to 0 and j to True
      >>> pymongo.version
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      NameError: name 'pymongo' is not defined
      >>>
      

      But the same connection string works as expected from mongo shell:

      MacBook-Pro-52:myApp darshanj$ mongo "mongodb://root:rootpass@127.0.0.1:27017/admin?authMechanism=SCRAM-SHA-1&w=0&journal=true"
      MongoDB shell version v4.2.8
      connecting to: mongodb://127.0.0.1:27017/admin?authMechanism=SCRAM-SHA-1&compressors=disabled&gssapiServiceName=mongodb&journal=true&w=0
      Implicit session: session { "id" : UUID("d744cd39-b32d-488c-888d-c4de0b2f0d68") }
      MongoDB server version: 4.2.11
      Server has startup warnings: 
      2020-12-14T11:47:59.151+0530 I  CONTROL  [initandlisten] 
      2020-12-14T11:47:59.158+0530 I  CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
      MongoDB Enterprise > show dbs
      admin   0.000GB
      config  0.000GB
      local   0.000GB
      mydb    0.000GB
      test    0.004GB
      MongoDB Enterprise > use mydb
      switched to db mydb
      MongoDB Enterprise > db.mytab.insert({a:"m"})
      WriteResult({ "nInserted" : 1 })
      MongoDB Enterprise > 
      

      Our documentation should be updated with these points that w:0 with j:true is not allowed if connection is from driver.

      Thanks,
      Darshan

      Scope of changes

      Impact to Other Docs

      MVP (Work and Date)

      Resources (Scope or Design Docs, Invision, etc.)

            Assignee:
            emet.ozar@mongodb.com Emet Ozar
            Reporter:
            darshan.jayarama@mongodb.com Darshan Jayarama
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:
              1 year, 25 weeks ago