[CXX-790] How to bulk upsert using mongodb c++11 driver? Created: 28/Dec/15  Updated: 11/Sep/19  Resolved: 05/Jan/16

Status: Closed
Project: C++ Driver
Component/s: Documentation
Affects Version/s: None
Fix Version/s: 3.0.0-rc0

Type: Task Priority: Minor - P4
Reporter: Amit Ambasta Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: C++11 Driver MongoDB 3.2

 Description   

Hi,

In the current examples, I don't see a way to bulk upsert documents against a collection. How should one go about doing so?



 Comments   
Comment by Amit Ambasta [ 05/Jan/16 ]

Thanks a lot tess.avitabile and acm

Comment by Tess Avitabile (Inactive) [ 05/Jan/16 ]

Hi amit.ambasta@delhivery.com. You can now find a general example on bulk write operations at https://github.com/mongodb/mongo-cxx-driver/blob/master/examples/mongocxx/bulk_write.cpp.

Comment by Githook User [ 05/Jan/16 ]

Author:

{u'username': u'tessavitabile', u'name': u'Tess Avitabile', u'email': u'tess.avitabile@mongodb.com'}

Message: CXX-790 - Bulk write example
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/79090cbb8c42337904b2cbabfbb6553caf15cb1f

Comment by Andrew Morrow (Inactive) [ 29/Dec/15 ]

Hi amit.ambasta@delhivery.com - We will work on some examples to demonstrate how to construct bulk operations to make this clearer.

Comment by Amit Ambasta [ 29/Dec/15 ]

Currently I am doing,

write.cxx

// Mongo Collection
mongocxx::collection c;
c.bulk_write {
    mongocxx::bulk_write {false}.append(
        mongocxx::model::write {
            mongocxx::model::update_one{
                bsoncxx::builder::stream::document {}.view(),
                bsoncxx::builder::stream::document {}.view()
            }.upsert(true)
        }
    )// append more as needed
}

Is this the right way? If so, then it seems quite complicated!

Generated at Wed Feb 07 22:00:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.