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

Flexible opts for bulk operations

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.0
    • Affects Version/s: None
    • Component/s: Bulk API, libmongoc
    • None
    • Fully Compatible

      Implement these new functions:

      bool mongoc_bulk_operation_remove_with_opts      (mongoc_bulk_operation_t       *bulk,
                                                        const bson_t                  *selector,
                                                        const bson_t                  *opts,
                                                        bson_error_t                  *error); /* OUT */
      bool mongoc_bulk_operation_remove_one_with_opts  (mongoc_bulk_operation_t       *bulk,
                                                        const bson_t                  *selector,
                                                        const bson_t                  *opts,
                                                        bson_error_t                  *error); /* OUT */
      bool mongoc_bulk_operation_replace_one_with_opts (mongoc_bulk_operation_t       *bulk,
                                                        const bson_t                  *selector,
                                                        const bson_t                  *document,
                                                        const bson_t                  *opts,
                                                        bson_error_t                  *error); /* OUT */
      bool mongoc_bulk_operation_update_with_opts      (mongoc_bulk_operation_t       *bulk,
                                                        const bson_t                  *selector,
                                                        const bson_t                  *document,
                                                        const bson_t                  *opts,
                                                        bson_error_t                  *error); /* OUT */
      bool mongoc_bulk_operation_update_one_with_opts  (mongoc_bulk_operation_t       *bulk,
                                                        const bson_t                  *selector,
                                                        const bson_t                  *document,
                                                        const bson_t                  *opts,
                                                        bson_error_t                  *error); /* OUT */
      

      "opts" can be NULL. I think each function appends "opts" to the operation without any validation. Example for write commands:

         opts = BCON_NEW ("upsert", BCON_BOOL (true));
         query = BCON_NEW ("_id", BCON_INT32 (4));
         doc = BCON_NEW ("$inc", "{", "j", BCON_INT32 (1), "}");
         mongoc_bulk_operation_update_with_opts (bulk, query, doc, opts);
      

      This produces:

      {update: "collection", 
       updates: [{
          q: {_id: 4}, 
          u: {$inc: {j: 1}}, 
          upsert: true
      }]}
      

      Another example:

         /* "One" normally sorts before "one"; make "one" come first */
         opts = BCON_NEW ("collation", "{",
                          "locale", BCON_UTF8 ("en_US"),
                          "caseFirst", BCON_UTF8 ("lower"),
                          "}");
      
         /* set x=1 on the document with _id "One", which now sorts after "one" */
         update = BCON_NEW ("$set", "{", "x", BCON_INT64 (1), "}");
         selector = BCON_NEW ("_id", "{", "$gt", BCON_UTF8 ("one"), "}");
         mongoc_bulk_operation_update_one_with_opts (bulk,
                                                     selector,
                                                     update,
                                                     opts);
      

      Produces:

      {update: "collection", 
       updates: [{
          q: {_id: "one"}, 
          u: {$set: {x: 1}}, 
          collation: {locale: "en_US", caseFirst: "lower"}
      }]}
      

      Once this is complete, re-enable the bulk upsert and bulk collation examples by reverting this commit:

      https://github.com/mongodb/mongo-c-driver/commit/a497587867fe28dac954d0244ca6fb4bfc5e4a38

      (Yes, revert the revert.)

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

              Created:
              Updated:
              Resolved: