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

How to upsert a replace_one in C++11 driver?

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: 3.0.1
    • Component/s: Implementation
    • Labels:
      None
    • Environment:
      Windows 10
      MS VS 2015
      MongoDB 3.3.5
      MongoDB C++11 Driver 3.0.1

      According to the update tutorial to replace one:

      db[this->id()].replace_one(filter_builder.view(), bsb_file_blueprint.view());

      It goes on to state:

      By specifying the upsert option to true, the update operation either updates matching document(s) or inserts a new document if no matching document exists.

      referring me to the C++11 documentation but without an example.

      I have (using the bulk_write.cpp example):

      {{mongocxx::model::replace_one upsert_op(filter_builder.view(), bsb_file_blueprint.view());
      upsert_op.upsert(true);}}

      But I'm unsure what to do next. Am I to do a bulk_write? Is there an easier way?

            Assignee:
            Unassigned Unassigned
            Reporter:
            therefore George Thompson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: