<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 22:00:48 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CXX-925] How to upsert a replace_one in C++11 driver?</title>
                <link>https://jira.mongodb.org/browse/CXX-925</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;According to the &lt;a href=&quot;https://docs.mongodb.com/getting-started/cpp/update/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;update tutorial&lt;/a&gt; to replace one:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;db&lt;span class=&quot;error&quot;&gt;&amp;#91;this-&amp;gt;id()&amp;#93;&lt;/span&gt;.replace_one(filter_builder.view(), bsb_file_blueprint.view());&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;It goes on to state:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;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. &lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;referring me to the C++11 documentation but without an example.&lt;/p&gt;

&lt;p&gt;I have (using the bulk_write.cpp example):&lt;/p&gt;

&lt;p&gt;{{mongocxx::model::replace_one upsert_op(filter_builder.view(), bsb_file_blueprint.view());&lt;br/&gt;
upsert_op.upsert(true);}}&lt;/p&gt;

&lt;p&gt;But I&apos;m unsure what to do next.  Am I to do a bulk_write? Is there an easier way?&lt;/p&gt;</description>
                <environment>Windows 10&lt;br/&gt;
MS VS 2015&lt;br/&gt;
MongoDB 3.3.5&lt;br/&gt;
MongoDB C++11 Driver 3.0.1</environment>
        <key id="292568">CXX-925</key>
            <summary>How to upsert a replace_one in C++11 driver?</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="5" iconUrl="https://jira.mongodb.org/images/icons/priorities/trivial.svg">Trivial - P5</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="therefore">George Thompson</reporter>
                        <labels>
                    </labels>
                <created>Wed, 8 Jun 2016 22:51:34 +0000</created>
                <updated>Wed, 11 Sep 2019 19:06:17 +0000</updated>
                            <resolved>Mon, 13 Jun 2016 20:05:26 +0000</resolved>
                                    <version>3.0.1</version>
                                                    <component>Implementation</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="1288814" author="therefore" created="Thu, 9 Jun 2016 00:35:28 +0000"  >&lt;p&gt;Thank you Andrew. I was focusing on the &lt;a href=&quot;http://mongodb.github.io/mongo-cxx-driver/classmongocxx_1_1model_1_1replace__one.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongocxx::model::replace_one&lt;/a&gt; linked from the &lt;a href=&quot;https://docs.mongodb.com/getting-started/cpp/update/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;tutorial&lt;/a&gt; when, naturally, I should have been focusing on &lt;a href=&quot;http://mongodb.github.io/mongo-cxx-driver/classmongocxx_1_1collection.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongocxx::collection class&lt;/a&gt;. I have an entire tab group dedicated to the c+11 classes and I should have caught that easily.&lt;/p&gt;

&lt;p&gt;Possibly the tutorial should point to the collection class vs. model?&lt;/p&gt;

&lt;p&gt;Thanks as always.&lt;/p&gt;</comment>
                            <comment id="1288755" author="acm" created="Wed, 8 Jun 2016 23:26:02 +0000"  >&lt;p&gt;There are two ways to do what you want:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;You can create an instance of mongocxx::model::replace_one, with the filter, replacement, and upsert flag set as you want, wrap the replace_one object up in a mongocxx::bulk_write object, and then use collection::bulk_write to issue it.&lt;/li&gt;
	&lt;li&gt;You can use mongocxx::collection::replace_one, passing the filter and replacement as arguments, along with a mongocxx::options::update object with the upsert flag set as you want.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;In fact, the latter method is just shorthand for the first. You may find looking at the implementation of mongocxx::collection::replace_one helpful:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/blob/d20926ba607e110b7fd699e1cfe0e3ddcfa0bf01/src/mongocxx/collection.cpp#L353-L376&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/blob/d20926ba607e110b7fd699e1cfe0e3ddcfa0bf01/src/mongocxx/collection.cpp#L353-L376&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                                        </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hsmbov:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="1064">Platforms 16 (06/24/16)</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>