Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-261

Omit default read and write concern from commands

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.2.0
    • Affects Version/s: 1.1.1
    • Component/s: None
    • None

      Quoting a comment from mongodb/mongo-php-library#326:

      If the library can have a notion of an unset read concern, read preference, and write concern, that would allow us to not pass that around the selected objects (e.g. Database, Collection, Bucket) and inject it into each operation.

      Currently, the library selects the read concern, read preference, and write concern after a MongoDB\Driver\Manager is constructed and passes that amongst its classes. As such, those classes have no way of knowing if the values were specified by a user or the driver's defaults. This is relevant for things like write concern, where the driver need not include a default write concern in commands.

      There are some implications for libmongoc here. Although it always omits applying a default read concern (i.e. "{}") to queries, based on 3e34af3 (for CDRIVER-1527), it lacks equivalent logic for write concerns. CDRIVER-1322 included a function to detect default write concerns, but logic in 3e34af3 (also for CDRIVER-1527) appears to include a default write concern so long as the option is specified. Since PHPLIB currently always provides a write concern to commands, we do see it sent across the wire:

      2017-01-17T16:40:59.966-0500 I COMMAND  [conn1] command test.foo command: insert { insert: "foo", writeConcern: {}, ordered: true, documents: [ { x: 1, _id: ObjectId('587e8f6b6118fd4a0c5acbf2') } ] } ninserted:1 keysInserted:1 numYields:0 reslen:44 locks:{ Global: { acquireCount: { r: 3, w: 3 } }, Database: { acquireCount: { w: 2, W: 1 } }, Collection: { acquireCount: { w: 2 } } } protocol:op_query 3ms
      ...
      2017-01-17T16:45:33.064-0500 I COMMAND  [conn2] command test.foo command: findAndModify { findAndModify: "foo", new: false, upsert: false, query: { x: 1 }, update: { $set: { y: 1 } }, writeConcern: {} } planSummary: COLLSCAN update: { $set: { y: 1 } } keysExamined:0 docsExamined:1 nMatched:1 nModified:1 numYields:0 reslen:120 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_query 0ms
      

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: