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

Updating entire document without operators such as set fails at execution with Cannot do an empty bulk write

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 0.2.0
    • Component/s: Implementation
    • None

      As per mongodb documentation, updating entire document is possible as:

      update.js
      db.people.update(
         { name: "Andy" },
         {
            name: "Andy",
            rating: 1,
            score: 1
         },
         { upsert: true }
      )
      

      One need provide update operators such as $set only when updating sub-document. The same should be achieveable with the C++11 driver as:

      update.cxx
          {
              // @begin: cpp-update-top-level-fields
              bsoncxx::builder::stream::document filter_builder, update_builder;
              filter_builder << "name"
                             << "Juni";
              update_builder << "cuisine"
                             << "American (New)";
      
              db["restaurants"].update_one(filter_builder.view(), update_builder.view());
              // @end: cpp-update-top-level-fields
          }
      

      However, executing the above code leads to
      terminate called after throwing an instance of

      stderr
      'mongocxx::v0::bulk_write_exception'
        what():  Cannot do an empty bulk write: mongoc command_invalid_arg error
      

            Assignee:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Reporter:
            amit.ambasta@delhivery.com Amit Ambasta
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: