<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:26:17 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>[DRIVERS-2725] BulkWriteResult.insertedIds does not reflect actual inserted documents</title>
                <link>https://jira.mongodb.org/browse/DRIVERS-2725</link>
                <project id="10980" key="DRIVERS">Drivers</project>
                    <description>&lt;div class=&quot;panel&quot; style=&quot;background-color: #fafbfc;border-width: 1px;&quot;&gt;&lt;div class=&quot;panelContent&quot; style=&quot;background-color: #fafbfc;&quot;&gt;
&lt;h3&gt;&lt;a name=&quot;Summary&quot;&gt;&lt;/a&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;/h3&gt;

&lt;p&gt;Currently, the drivers specification for BulkWriteResult provides an optional property `insertedIds` (see &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#bulk-write-models&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;CRUD spec&lt;/a&gt;,  &lt;a href=&quot;https://www.mongodb.com/docs/manual/reference/method/BulkWriteResult/#mongodb-data-BulkWriteResult.insertedIds&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;MongoDB manual&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;A user on Version 5.6.0 of the Node Driver reported the following bug on BulkWriteResult.insertedIds: If there are writeErrors and an _id is not correctly inserted, it will still incorrectly appear in the insertedIds Object.&lt;/p&gt;

&lt;p&gt;This bug likely reproduce on other drivers variations that support BulkWriteResult.insertedIds.&lt;/p&gt;
&lt;h3&gt;&lt;a name=&quot;Motivation&quot;&gt;&lt;/a&gt;&lt;b&gt;Motivation&lt;/b&gt;&lt;/h3&gt;
&lt;h4&gt;&lt;a name=&quot;Whoistheaffectedenduser%3F&quot;&gt;&lt;/a&gt;Who is the affected end user?&lt;/h4&gt;

&lt;p&gt;The affected end user is any user using BulkWrite or InsertMany with inserts that contain any errors.&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Howdoesthisaffecttheenduser%3F&quot;&gt;&lt;/a&gt;How does this affect the end user?&lt;/h4&gt;

&lt;p&gt;In the event of an error case, the user will be confused as to which _ids were inserted. This is because BulkWriteResult.writeErrors will signal that certain inserts were unsuccessful, but BulkWriteResult.insertedIds will include all attempted inserts.&lt;/p&gt;

&lt;p&gt;This can lead the user to be misinformed on which inserts were successful.&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Howlikelyisitthatthisproblemorusecasewilloccur%3F&quot;&gt;&lt;/a&gt;How likely is it that this problem or use case will occur?&lt;/h4&gt;

&lt;p&gt;Edge Case&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Iftheproblemdoesoccur%2Cwhataretheconsequencesandhowseverearethey%3F&quot;&gt;&lt;/a&gt;If the problem does occur, what are the consequences and how severe are they?&lt;/h4&gt;

&lt;p&gt;Misinformation, potentially minor&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Isthisissueurgent%3F&quot;&gt;&lt;/a&gt;Is this issue urgent?&lt;/h4&gt;

&lt;p&gt;N/A&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Isthisticketrequiredbyadownstreamteam%3F&quot;&gt;&lt;/a&gt;Is this ticket required by a downstream team?&lt;/h4&gt;

&lt;p&gt;May affect Mongosh&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Isthisticketonlyfortests%3F&quot;&gt;&lt;/a&gt;Is this ticket only for tests?&lt;/h4&gt;

&lt;p&gt;No&lt;/p&gt;
&lt;h3&gt;&lt;a name=&quot;AcceptanceCriteria&quot;&gt;&lt;/a&gt;&lt;b&gt;Acceptance Criteria&lt;/b&gt;&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;BulkWrite and InsertMany support insertedIds correctly, in that insertedIds only includes index and _id pairs that were actually inserted&lt;/li&gt;
	&lt;li&gt;Tests cover unordered and ordered inserts, as well as inserts with multiple errors&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
        <key id="2443911">DRIVERS-2725</key>
            <summary>BulkWriteResult.insertedIds does not reflect actual inserted documents</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="aditi.khare@mongodb.com">Aditi Khare</reporter>
                        <labels>
                            <label>leads-triage</label>
                    </labels>
                <created>Fri, 15 Sep 2023 20:41:54 +0000</created>
                <updated>Tue, 19 Sep 2023 16:43:31 +0000</updated>
                                                                <component>CRUD</component>
                                        <votes>0</votes>
                                    <watches>7</watches>
                                                                                                                <comments>
                            <comment id="5710103" author="jmikola@gmail.com" created="Mon, 18 Sep 2023 00:54:28 +0000"  >&lt;p&gt;I believe this exact behavior was previously discussed in SPEC-82, where the outcome was to allow drivers to report the auto-generated ID even in the event of a write error. &lt;/p&gt;

&lt;p&gt;The current wording of the CRUD spec does not address how to populate or interpret &lt;tt&gt;insertedIds&lt;/tt&gt; when dealing with write errors, so the first step would be making a spec change to clarify that one way or another.&lt;/p&gt;

&lt;p&gt;If we keep the existing behavior, the spec could be improved to mention that &lt;tt&gt;insertedIds&lt;/tt&gt; may contain IDs of failed inserts and that the map should be interpreted alongside &lt;tt&gt;writeErrors&lt;/tt&gt; to infer exactly which IDs were successfully inserted.&lt;/p&gt;

&lt;p&gt;Whether we keep the existing behavior or change it (to prune &lt;tt&gt;insertedIds&lt;/tt&gt; of errored inserts), we can consider adding test coverage.&lt;/p&gt;

&lt;p&gt;This could be tested using &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/unified-test-format/unified-test-format.rst#expectederror&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;expectedError.expectResult&lt;/a&gt; in the Unified Test Format to assert that erroneous inserts (e.g. duplicate key violations) are pruned from the &lt;tt&gt;insertedIds&lt;/tt&gt; map on the &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#write-results&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;BulkWriteResult&lt;/a&gt; exposed on a &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#writeerror&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;BulkWriteError&lt;/a&gt;. An additional test could also be created for &lt;tt&gt;insertMany&lt;/tt&gt; operations, since those also throw BulkWriteError exceptions.&lt;/p&gt;

&lt;p&gt;Since the &lt;tt&gt;insertedIds&lt;/tt&gt; map is optional, these tests should use &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/unified-test-format/unified-test-format.rst#unsetormatches&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;&lt;tt&gt;$$unsetOrMatches&lt;/tt&gt;&lt;/a&gt; for their assertions (as is done in existing non-error tests for &lt;tt&gt;insertedIds&lt;/tt&gt;).&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="2386270">NODE-5421</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="900346">DRIVERS-716</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </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_10951" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Driver Changes</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10748"><![CDATA[Needed]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i28skg:</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>