Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-837

Add support for the readConcern option

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.3.0-beta0
    • Affects Version/s: None
    • Component/s: libmongoc
    • None

      https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#location-specification

      ReadConcern SHOULD be specifiable at the Client, Database, and Collection levels. Unless specified, the value MUST be inherited from its parent and SHOULD NOT be modifiable on an existing Client, Database, and Collection. In addition, a driver MAY allow it to be specified on a per-operation basis in accordance with the CRUD specification.

      mongoc will support setting readConcern on:

      • mongoc_collection_t
      • mongoc_database_t
      • mongoc_client_t

      mongoc will not support setting readConcern on per-operation basis, and will therefore not be adding extended versions of helpers that could otherwise take readConcern.

      The following helpers (that support readConcern in MongoDB 3.2+) are currently implemented in mongoc:

      • mongoc_collection_count
      • mongoc_collection_find
      • mongoc_collection_aggregate

      When using these helpers, readConcern must be set on the collection level, e.g.:

      mongoc_collection_set_read_concern (collection, read_concern);
      mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, NULL, NULL, read_prefs);
      

      Other currently known commands that support readConcern, but don't have helpers in mongoc are:

      • mapReduce when the result is inline
      • distinct
      • parallelCollectionScan
      • geoNear
      • geoSearch

      The following are new (public API) functions handling read_concern:

      #define MONGOC_READ_CONCERN_LEVEL_LOCAL    "local"
      #define MONGOC_READ_CONCERN_LEVEL_MAJORITY "majority"
      
      typedef struct _mongoc_read_concern_t mongoc_read_concern_t;
      
      mongoc_read_concern_t        *mongoc_read_concern_new            (void);
      mongoc_read_concern_t        *mongoc_read_concern_copy           (const mongoc_read_concern_t  *read_concern);
      void                          mongoc_read_concern_destroy        (mongoc_read_concern_t        *read_concern);
      const char                   *mongoc_read_concern_get_level      (const mongoc_read_concern_t  *read_concern);
      bool                          mongoc_read_concern_set_level      (mongoc_read_concern_t        *read_concern, const char *level);
      
      const mongoc_read_concern_t  *mongoc_client_get_read_concern     (const mongoc_client_t        *client);
      void                          mongoc_client_set_read_concern     (mongoc_client_t              *client,       const mongoc_read_concern_t *read_concern);
      
      const mongoc_read_concern_t  *mongoc_database_get_read_concern   (const mongoc_database_t      *database);
      void                          mongoc_database_set_read_concern   (mongoc_database_t            *database,     const mongoc_read_concern_t *read_concern);
      
      const mongoc_read_concern_t  *mongoc_collection_get_read_concern (const mongoc_collection_t    *collection);
      void                          mongoc_collection_set_read_concern (mongoc_collection_t          *collection,   const mongoc_read_concern_t *read_concern);
      
      const mongoc_read_concern_t  *mongoc_uri_get_read_concern        (const mongoc_uri_t           *uri);
      

      Note: To use this feature in MongoDB 3.2 you must start mongod with --enableMajorityReadConcern

      Note that the comments on this ticket assumed that we would have to support readConcern as an option to the find helper, and therefore requiring a new extended version of that helper.
      This is however not correct and was based on misunderstanding of the specification.

            Assignee:
            bjori Hannes Magnusson
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: