<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 06:06: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>[SERVER-66740] findAndModify.lastErrorObject.updatedExisting always true after and update</title>
                <link>https://jira.mongodb.org/browse/SERVER-66740</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I&apos;ve noticed an issue with findAndModify, where updatedExisting always return true when updating a field with the same value.&lt;/p&gt;

&lt;p&gt;I found this blog post that describe the issue well: &lt;a href=&quot;https://codehunter.cc/a/mongodb/findandupdate-how-to-check-if-document-was-really-updated&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://codehunter.cc/a/mongodb/findandupdate-how-to-check-if-document-was-really-updated&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although this behavior seems to be a bug, it&apos;s in line with the documention: &lt;a href=&quot;https://www.mongodb.com/docs/manual/reference/command/findAndModify/#lasterrorobject.&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://www.mongodb.com/docs/manual/reference/command/findAndModify/#lasterrorobject&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, I would expect updatedExisting to be true if the document was upserted or if any modification was done to the existing document. Similar to how the update command output: &lt;a href=&quot;https://www.mongodb.com/docs/manual/reference/command/update/#mongodb-data-update.nModified.&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://www.mongodb.com/docs/manual/reference/command/update/#mongodb-data-update.nModified&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Might be related to this other issue: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-12329&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/SERVER-12329&lt;/a&gt;&lt;/p&gt;</description>
                <environment></environment>
        <key id="2054465">SERVER-66740</key>
            <summary>findAndModify.lastErrorObject.updatedExisting always true after and update</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="3">Duplicate</resolution>
                                        <assignee username="chris.kelly@mongodb.com">Chris Kelly</assignee>
                                    <reporter username="sacadieux@ea.com">Samuel Cadieux</reporter>
                        <labels>
                    </labels>
                <created>Wed, 25 May 2022 03:29:45 +0000</created>
                <updated>Fri, 1 Jul 2022 16:01:15 +0000</updated>
                            <resolved>Fri, 3 Jun 2022 12:47:29 +0000</resolved>
                                    <version>5.0.6</version>
                                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="4592844" author="JIRAUSER1269111" created="Fri, 3 Jun 2022 13:53:36 +0000"  >&lt;p&gt;Hi Chris, indeed &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-28145&quot; title=&quot;add ability to obtain modified flag from findOneAndUpdate result&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-28145&quot;&gt;SERVER-28145&lt;/a&gt; from 2017 would solve this issue, but I&apos;m hoping the priority on this issue would be increased.&lt;/p&gt;

&lt;p&gt;We currently don&apos;t have a reliable way to tell what whether the result of a findAndModify operation was a no-op and we rely on this information in our system to notify state updates.&lt;/p&gt;

&lt;p&gt;We&apos;ve identified a few workarounds, but none is perfect or reliable. Can you think of a better workaround in the meantime?&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Workaround 1: Use update instead of findAndModify&lt;/b&gt;&lt;br/&gt;
Currently, we&apos;re forced to use the update command instead. However, the update command doesn&apos;t return the result of the operation, requiring a second command to pull out the updated document.&lt;/p&gt;

&lt;p&gt;This is an acceptable workaround if we query the document using a unique index.&lt;/p&gt;

&lt;p&gt;However, problems arise if we need to update a document using a filter that is not unique.&lt;br/&gt;
Or worse yet, if the update definition modifies fields part of the filter definition, this makes it impossible to find the document that was updated.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Workaround2: Client-side comparison&lt;/b&gt;&lt;br/&gt;
A more costly workaround would be to use findAndModify but request the document in its previous state. And do a second query to get the updated document using the document id from the previous state and perform a client-side comparison. This almost solves our issue, however this might cause false positives given that the document might have been updated by another instance of our service.&lt;/p&gt;</comment>
                            <comment id="4592652" author="JIRAUSER1265262" created="Fri, 3 Jun 2022 12:33:17 +0000"  >&lt;p&gt;Hi Samuel,&lt;/p&gt;

&lt;p&gt;Thanks for your report. According to the documentation, updatedExisting will be true if either of the following occur:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Modified an existing document.&lt;/li&gt;
	&lt;li&gt;Found the document, but it was already in the desired destination state so no update actually occurred.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;In this case, when you first create the document this will be false, but running the findAndModify query while the document is in the desired destination state already will cause it to return true.&lt;/p&gt;

&lt;p&gt;Adding extra information indicating whether changes were made (like nModified) is on the backlog in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-28145&quot; title=&quot;add ability to obtain modified flag from findOneAndUpdate result&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-28145&quot;&gt;SERVER-28145&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Regards,&lt;br/&gt;
Christopher&lt;/p&gt;</comment>
                            <comment id="4571248" author="JIRAUSER1269111" created="Wed, 25 May 2022 03:37:27 +0000"  >&lt;p&gt;To reproduce, run the following command twice using mongosh:&lt;br/&gt;
&lt;tt&gt;db.runCommand({ &quot;findAndModify&quot; : &quot;collection&quot;, &quot;query&quot; : { &quot;_id&quot; : ObjectId(&quot;628d26b2f8221751cdd7dcd2&quot;) }, &quot;update&quot; : { &quot;$set&quot; : { &quot;name&quot; : &quot;some name&quot; } }, &quot;new&quot;: true, &quot;upsert&quot;: true })&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Notice how the output of the second execution returns:&lt;br/&gt;
&lt;tt&gt;lastErrorObject: { n: 1, &lt;font color=&quot;#FF0000&quot;&gt;&lt;b&gt;updatedExisting: true&lt;/b&gt; &lt;/font&gt;},&lt;/tt&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="358143">SERVER-28145</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="358143">SERVER-28145</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Fri, 3 Jun 2022 12:33:17 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        1 year, 35 weeks, 5 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>dbeng-pm-bot</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            1 year, 35 weeks, 5 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                    <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10026"><![CDATA[ALL]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>chris.kelly@mongodb.com</customfieldvalue>
            <customfieldvalue>sacadieux@ea.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i0w6gn:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i0f2ig:</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_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10750" key="com.atlassian.jira.plugin.system.customfieldtypes:textarea">
                        <customfieldname>Steps To Reproduce</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>&lt;ol&gt;
	&lt;li&gt;&lt;tt&gt;Use Mongo 5.0.6&lt;/tt&gt;&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;Run the following commmand to insert a document:&lt;/tt&gt;&lt;br/&gt;
{{&amp;gt; db.runCommand({ &quot;findAndModify&quot; : &quot;collection&quot;, &quot;query&quot; : 
{ &quot;_id&quot; : ObjectId(&quot;628d26b2f8221751cdd7dcd2&quot;) }
&lt;p&gt;, &quot;update&quot; : { &quot;$set&quot; : &lt;/p&gt;
{ &quot;name&quot; : &quot;some name&quot; }
&lt;p&gt; }, &quot;new&quot;: true, &quot;upsert&quot;: true })}}&lt;br/&gt;
{{}}&lt;/p&gt;&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;Run the following command to update the document with the same values:&lt;/tt&gt;{&lt;tt&gt;}&lt;/tt&gt;{{{}&amp;gt; db.runCommand({ &quot;findAndModify&quot; : &quot;collection&quot;, &quot;query&quot; : 
{ &quot;_id&quot; : ObjectId(&quot;628d26b2f8221751cdd7dcd2&quot;) }
&lt;p&gt;, &quot;update&quot; : { &quot;$set&quot; : &lt;/p&gt;
{ &quot;name&quot; : &quot;some name&quot; }
&lt;p&gt; }, &quot;new&quot;: true, &quot;upsert&quot;: true }){}}}&lt;br/&gt;
{{}}&lt;/p&gt;&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;Observe the result state:&lt;/tt&gt;&lt;br/&gt;
{{{}lastErrorObject: 
&lt;div class=&quot;error&quot;&gt;&lt;span class=&quot;error&quot;&gt;Unknown macro: { n}&lt;/span&gt; &lt;/div&gt;
&lt;p&gt;,{}}}{&lt;tt&gt;}&lt;/tt&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                    <customfieldvalue><![CDATA[chris.kelly@mongodb.com]]></customfieldvalue>
    

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i0vslz:</customfieldvalue>

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