<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:00:44 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-2635] findAndModify() and getLastError() Problem</title>
                <link>https://jira.mongodb.org/browse/SERVER-2635</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;When using the &quot;findAndModify&quot; command, &quot;getLastError&quot; only returns the result of the last of the two operations. By default, this means it returns the result of the &quot;update&quot; operation (which is normally desirable), but when one uses the &quot;new&quot; option, getLastError returns the result of the &quot;find&quot; operation, so any error in the update clause is inaccessible.&lt;/p&gt;

&lt;p&gt;The following sequence of commands demonstrates the problem:&lt;br/&gt;
db.test.insert(&lt;/p&gt;
{name: &apos;bob&apos;}
&lt;p&gt;)&lt;br/&gt;
db.test.findAndModify({query: &lt;/p&gt;
{name: &apos;bob&apos;}
&lt;p&gt;, update: {$set: &lt;/p&gt;
{age: 30}
&lt;p&gt;, $inc: {age: 3}}, new: true})&lt;br/&gt;
db.getLastError()&lt;/p&gt;

&lt;p&gt;Ideally, what you should receive when you run the last line, db.getLastError(), you should get an error &quot;Field name duplication not allowed with modifiers&quot;. Instead, you get null, as the find operation (the 2nd of the two internal operations), succeeded. If you had the &quot;new&quot; option set to false, and you had a similar error in the find/query portion of the command, you&apos;d get the same problem.&lt;/p&gt;</description>
                <environment>Mac OS X 10.6.6; MongoDB 1.6.5</environment>
        <key id="14917">SERVER-2635</key>
            <summary>findAndModify() and getLastError() Problem</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="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="wardrop">Tom Wardrop</reporter>
                        <labels>
                    </labels>
                <created>Mon, 28 Feb 2011 11:39:30 +0000</created>
                <updated>Thu, 17 Mar 2011 19:13:13 +0000</updated>
                            <resolved>Mon, 28 Feb 2011 15:29:32 +0000</resolved>
                                    <version>1.6.5</version>
                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="24932" author="wardrop" created="Tue, 1 Mar 2011 09:35:25 +0000"  >&lt;p&gt;I just tried 1.8.0-rc0 and nothing seems to be any different. findAndModify seems to behave exactly the same. Eliot, have you tried the two commands I posted earlier? Try running them in 1.8, and tell me exactly what you get. I get...&lt;/p&gt;

&lt;p&gt;{&lt;br/&gt;
	&quot;value&quot; : &lt;/p&gt;
{
		&quot;_id&quot; : ObjectId(&quot;4d6cbd941ee2917751580cab&quot;),
		&quot;name&quot; : &quot;bob&quot;
	}
&lt;p&gt;,&lt;br/&gt;
	&quot;ok&quot; : 1&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Which is obviously not what I would have expected. I&apos;m expecting to see an error regarding the conflict in the update clause.&lt;/p&gt;

&lt;p&gt;EDIT: Whoops, I wasn&apos;t actually running 1.8.0-rc0. I used version() and it reported 1.8.0-rc0, but I now found out that version() returns the client version, and db.version() returns the server version. A little confusing, but I hopefully won&apos;t make that mistake again. Indeed, 1.8.0-rc0 does seem to have the fix you mention. Thanks.&lt;/p&gt;</comment>
                            <comment id="24892" author="wardrop" created="Mon, 28 Feb 2011 23:04:28 +0000"  >&lt;p&gt;Ah ha, now that&apos;s the answer I was after &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt; I&apos;ll have to hang out for 1.8 then. Thanks.&lt;/p&gt;</comment>
                            <comment id="24884" author="eliot" created="Mon, 28 Feb 2011 22:45:41 +0000"  >&lt;p&gt;That&apos;s a bug with the findAndModify command itself, which was fixed in 1.7 and works as expected in 1.8.0-rc0&lt;/p&gt;</comment>
                            <comment id="24882" author="wardrop" created="Mon, 28 Feb 2011 22:42:28 +0000"  >&lt;p&gt;Hi Eliot,&lt;/p&gt;

&lt;p&gt;I don&apos;t believe the problem is resolved. Sure, as you say, this may be by design, but that still doesn&apos;t answer the question: How do I get error messages from findAndModify? How do I know whether the update portion of the command as succeeded or not?&lt;/p&gt;

&lt;p&gt;Going off what you said, running the following should give me an error in the return value:&lt;/p&gt;

&lt;p&gt;db.test.insert(&lt;/p&gt;
{name: &apos;bob&apos;}
&lt;p&gt;) &lt;br/&gt;
db.runCommand({findAndModify: &apos;test&apos;, query: &lt;/p&gt;
{name: &apos;bob&apos;}
&lt;p&gt;, update: {$set: &lt;/p&gt;
{age: 30}
&lt;p&gt;, $inc: {age: 3}}, new: true}) &lt;/p&gt;

&lt;p&gt;The update fails, but I&apos;m told nothing of it. Ironically however, if the find operation fails (i.e. doesn&apos;t find a match), then an error is returned &quot;No matching object found&quot;. So the problem is, how do I know whether the update in a findAndModify operation has succeeded or not?&lt;/p&gt;</comment>
                            <comment id="24823" author="eliot" created="Mon, 28 Feb 2011 15:29:32 +0000"  >&lt;p&gt;findAndModify is a command, meaning the error is returned in the result.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>5.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 28 Feb 2011 15:29:32 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        12 years, 51 weeks, 1 day 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>ian@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            12 years, 51 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </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>eliot</customfieldvalue>
            <customfieldvalue>wardrop</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrp57b:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>20860</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_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>
                                

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

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