Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-763

Overload methods that take options classes to take bson documents instead

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • API
    • None

    Description

      For some users and use cases, it is tedious/impractical to create options objects when calling driver methods that take them. We should provide overloads taking bsoncxx::document::view_or_value objects to make the driver more versatile and usable.

      Consider a case where the user has a bson document that they have stored options in, either generated from some config file or read out of the database:

      // aggregate options
      { "maxTimeMS" : 100, "explain" : true, "allowDiskUse" : false }
      

      In order to run an aggregation query, these options must first be converted to an options::aggregate object:

      bsoncxx::document::value agg_options_bson{some existing bson};
       
      options::aggregate opts{};
      opts.max_time_ms(agg_options_bson["maxTimeMS"].get_int64());
      opts.explain(agg_options_bson["explain"].get_bool());
      opts.allow_disk_use(agg_options_bson["allowDiskUse"].get_bool());
       
      collection.aggregate(pipeline, opts);
      

      If we provided an overload we could skip the options-building steps here and just pass in the original document:

      bsoncxx::document::value agg_options_bson{some existing bson};
      collection.aggregate(pipeline, agg_options_bson);
      

      Edit:

      Other methods that we should consider changing, in addition to collection::aggregate():

      • collection::create_index()

      Attachments

        Activity

          People

            Unassigned Unassigned
            samantha.ritter@mongodb.com Samantha Ritter (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: