<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:59:39 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-586] bulk API input parameter does not have &quot;fsync&quot; or &quot;journal&quot;, is fsync=false, journal=false always used?</title>
                <link>https://jira.mongodb.org/browse/CXX-586</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;Looks there are 2 ways to do the bulk insert:&lt;br/&gt;
1. the older way, i.e. insert a vector via mongo::DBClientConnection insert() API.&lt;br/&gt;
2. the newer way, i.e. use mongo::BulkOperationBuilder insert() and execute() API.&lt;/p&gt;

&lt;p&gt;To check errors for #1, we call getLastError(const std::string &amp;amp;db, bool fsync=false, bool journal =false, int writeconcern=0, int wtimeout=0)&lt;/p&gt;

&lt;p&gt;To check errors for #2, call mongo::BulkOperationBuilder execute (const WriteConcern *writeConcern, WriteResult *writeResult),  second parameter will provide the error code. &lt;/p&gt;

&lt;p&gt;For #2, the API allow us to specify writeconcern, but not fsync or journal.&lt;br/&gt;
I have following questions:&lt;/p&gt;

&lt;p&gt;1. is #2 the recommended way to do bulk operations?&lt;br/&gt;
2. If so, is there a way to specify fsync and journal when we use the #2 .&lt;br/&gt;
3. If we do not use bulk API, i.e. we insert 1 document at a time what is the recommended way to check errors?&lt;br/&gt;
4. Is that true that getLastError() is going to be deprecated? &lt;/p&gt;

&lt;p&gt;Thanks!&lt;br/&gt;
Judy&lt;/p&gt;</description>
                <environment></environment>
        <key id="199942">CXX-586</key>
            <summary>bulk API input parameter does not have &quot;fsync&quot; or &quot;journal&quot;, is fsync=false, journal=false always used?</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</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="Judy.Han">Judy Han [X]</reporter>
                        <labels>
                            <label>legacy-cxx</label>
                    </labels>
                <created>Thu, 23 Apr 2015 20:08:15 +0000</created>
                <updated>Wed, 11 Sep 2019 19:05:05 +0000</updated>
                            <resolved>Fri, 24 Apr 2015 18:14:02 +0000</resolved>
                                    <version>legacy-1.0.0</version>
                                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="897629" author="judy.han" created="Fri, 24 Apr 2015 18:11:29 +0000"  >&lt;p&gt;Got it. Thanks a lot for the explanation! Feel free to close the ticket.&lt;br/&gt;
Judy&lt;/p&gt;</comment>
                            <comment id="897622" author="adam.midvidy" created="Fri, 24 Apr 2015 18:05:00 +0000"  >&lt;p&gt;Judy regarding your latest question - if requiresConfirmation true, then the driver will do the equivalent of calling getLastError for you when you execute the write. If requiresConfirmation() is false, then you need to call getLastError() yourself to check if the write succeeded.&lt;/p&gt;</comment>
                            <comment id="897619" author="adam.midvidy" created="Fri, 24 Apr 2015 18:02:12 +0000"  >&lt;p&gt;For #1, when writing to a server with journaling enabled the effect of fsync(true) and journal(true) are exactly the same - the write will block until it has been written to the journal. fsync(true) ONLY has a different effect when journaling is NOT enabled on the server - then the write will block until it is fsync&apos;d to disk. Note that when a write is written to the journal it can not be lost, if the server crashes, it will be able to reconstruct the write from the journal.&lt;/p&gt;

&lt;p&gt;For additional questions you have about MongoDB (not the C++ driver) I would reach out on the mongodb-user email list, as people there will be better equipped to answer your questions.&lt;/p&gt;</comment>
                            <comment id="896970" author="judy.han" created="Fri, 24 Apr 2015 04:43:25 +0000"  >&lt;p&gt;Hi Adam,&lt;br/&gt;
For #2, thanks for the suggestion, I tried some tests, looks I have to use bulk.find().upsert().replaceOne() for my purpose, if I use bulk.find().replaceOne() directy it will only do the update, but not insert if the document does not alrady exist. thanks.&lt;/p&gt;

&lt;p&gt;For #1, when you say &quot;the effect is the same&quot;, do you mean set journal(true) or fsync(true) has the same effect? I thought journal(true) does not guarantee write to disk. I assume if fsync(true) means journal is automatically true? did I understand it correctly?&lt;/p&gt;

&lt;p&gt;Regarding using WriteConern class, I have a follow up question on:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;bool mongo::WriteConcern::requiresConfirmation() 	const&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    Whether we need to send getLastError for this WriteConcern.&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    The only time we don&apos;t require confirmation is when w is explicitly set to 0.&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;Does that mean I still need to call getLastError() unless I explicitly set _w to 0 ? (I assume it&apos;s &quot;_w&quot; since there is no &quot;w&quot;in this class) Please advise. Thanks!&lt;/p&gt;
</comment>
                            <comment id="896939" author="adam.midvidy" created="Fri, 24 Apr 2015 03:28:56 +0000"  >&lt;p&gt;Hi Judy,&lt;/p&gt;

&lt;p&gt;First off, in regards to my previous answer, note that journal(true) and fsync(true) should not be used together. I would only set journal(true) - assuming you are running with journaling enabled, the effect is the same. &lt;/p&gt;

&lt;p&gt;For your next question:&lt;br/&gt;
I would recommend using &quot;bulk upserts&quot; for your use-case. These are special updates that become inserts if the update is not matched.&lt;/p&gt;

&lt;p&gt;example:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;BulkOperationBuilder bulk(&amp;amp;conn, &quot;mydb.mycollection&quot;, false);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;bulk.find(BSON(&quot;_id&quot; &amp;lt;&amp;lt; 1 &amp;lt;&amp;lt; &quot;myKeyWithUniqueIndex&quot; &amp;lt;&amp;lt; 2))&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;       .replaceOne(BSON(&quot;_id&quot; &amp;lt;&amp;lt; 1 &amp;lt;&amp;lt; &quot;myKeyWithUniqueIndex&quot; &amp;lt;&amp;lt; 2 &amp;lt;&amp;lt; otherKey &amp;lt;&amp;lt; 3));&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;WriteResult res;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;bulk.execute(&amp;amp;WriteConcern::journaled, &amp;amp;res);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Any keys that are uniquely indexed (i.e. _id) should go in the selector passed to bulk.find(). Then you can pass the full document to replaceOne. If there is no document that matches the selector, the document will be inserted. If not, the document will be updated with the replacement, which avoids the &quot;duplicate key&quot; error.&lt;/p&gt;

&lt;p&gt;You can read more about upserts here: &lt;a href=&quot;http://docs.mongodb.org/manual/reference/method/Bulk.find.upsert/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/manual/reference/method/Bulk.find.upsert/&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="896924" author="judy.han" created="Fri, 24 Apr 2015 03:09:44 +0000"  >&lt;p&gt;Hi Adam,&lt;br/&gt;
Thank you very much for the information!&lt;br/&gt;
I did not realize WriteConcern object has the ability to set fsync and journal parameters. Thanks!&lt;br/&gt;
Another question:&lt;br/&gt;
Is there a way for bulk insert to ignore &quot;duplicate key&quot; error? The reason I need the non-bulk insert is for bulk insert failure case where I end up redo the insert one at a time just to figure out which one is a true failure and which one is from duplicate loading (may happen in our application but we consider it a success).&lt;br/&gt;
Thanks!&lt;br/&gt;
Judy&lt;/p&gt;</comment>
                            <comment id="896910" author="adam.midvidy" created="Fri, 24 Apr 2015 02:22:21 +0000"  >&lt;p&gt;Hi Judy, &lt;/p&gt;

&lt;p&gt;(1) BulkOperationBuilder is definitely the recommended way to do bulk operations.&lt;br/&gt;
(2) You can specify fsync and journal by calling fsync(true) and journal(true) on the WriteConcern object you pass to BulkOperationBuilder::execute.&lt;br/&gt;
(3) I would recommend using the Bulk API, even if you are only inserting 1 document. Then you should not even have to use getLastError().&lt;br/&gt;
(4) I think getLastError() will continue to work for the foreseeable future but its use is discouraged. I would recommend using the Bulk API and passing the appropriate WriteConcern even when inserting small numbers of documents.&lt;/p&gt;

&lt;p&gt;Please let me know if you have any more questions.&lt;/p&gt;</comment>
                    </comments>
                    <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|hs8ppj:</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>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>