<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 05:24:49 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-51208] New field `$setOnUpdate` will solve some problems</title>
                <link>https://jira.mongodb.org/browse/SERVER-51208</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Hello! My name is Vladimir Revenko. I am NodeJS developer and active MongoDB user!&lt;/p&gt;
&lt;h2&gt;&lt;a name=&quot;Problem&quot;&gt;&lt;/a&gt;Problem&lt;/h2&gt;

&lt;p&gt;Tools such as &lt;a href=&quot;https://github.com/Automattic/mongoose&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Mongoose&lt;/a&gt; use the &quot;timestamp&quot; functionality.&#160;This makes it difficult in some cases.&lt;/p&gt;

&lt;p&gt;If we run without a `&lt;tt&gt;timestamps`&lt;/tt&gt;&#160;parameter mongoose does this:&lt;/p&gt;

&lt;p&gt;{{db.cats.updateMany({}, { &apos;$set&apos;: &lt;/p&gt;
{ name: &apos;Zildjian&apos; }
&lt;p&gt; })}}&lt;/p&gt;

&lt;p&gt;MongoDB returns this:&lt;br/&gt;
`&lt;tt&gt;matchedCount&lt;/tt&gt;` &#8212; (`&lt;tt&gt;n&lt;/tt&gt;` in Mongoose) containing the number of matched documents;&lt;br/&gt;
`&lt;tt&gt;modifiedCount&lt;/tt&gt;` &#8212; (`&lt;tt&gt;nModified&lt;/tt&gt;` in Mongoose) containing the number of modified documents.&lt;/p&gt;

&lt;p&gt;But,&#160;if we run with `&lt;tt&gt;timestamps&lt;/tt&gt;` mongoose (with pre-hook) does this:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;db.cats.updateMany({}, {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &apos;$setOnInsert&apos;: {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; createdAt: new Date(&quot;Sat, 26 Sep 2020 17:56:54 GMT&quot;),&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; },&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &apos;$set&apos;: {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; updatedAt: new Date(&quot;Sat, 26 Sep 2020 17:56:54 GMT&quot;),&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; name: &apos;Zildjian&apos;,&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; },&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;})&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;even if a `&lt;tt&gt;name&lt;/tt&gt;` field is not modified, `&lt;tt&gt;updatedAt&lt;/tt&gt;` field has been modified and MongoDB will update all matched docs and `&lt;tt&gt;modifiedCount&lt;/tt&gt;` (`&lt;tt&gt;nModified&lt;/tt&gt;` in Mongoose) will always be equal to `&lt;tt&gt;matchedCount&lt;/tt&gt;` (`&lt;tt&gt;n&lt;/tt&gt;` in Mongoose).&lt;/p&gt;

&lt;p&gt;I think there are other examples, but timestamps are the most obvious example.&lt;/p&gt;
&lt;h2&gt;&lt;a name=&quot;Suggestionforimprovement&quot;&gt;&lt;/a&gt;Suggestion for improvement&lt;/h2&gt;

&lt;p&gt;Maybe you should separate the targeting update fields and the companion update fields at the mongodb level?&lt;/p&gt;

&lt;p&gt;Current usage works like this:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;db.cats.updateMany({}, {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &apos;$setOnInsert&apos;: {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; createdAt: new Date(&quot;Sat, 26 Sep 2020 17:56:54 GMT&quot;),&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; },&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &apos;$set&apos;: {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; updatedAt: new Date(&quot;Sat, 26 Sep 2020 17:56:54 GMT&quot;),&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; name: &apos;Zildjian&apos;,&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; },&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;})&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;New usage could be like this:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;db.cats.updateMany({}, {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &apos;$setOnInsert&apos;: {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; createdAt: new Date(&quot;Sat, 26 Sep 2020 17:56:54 GMT&quot;),&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; },&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &apos;$setOnUpdate&apos;: {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; updatedAt: new Date(&quot;Sat, 26 Sep 2020 17:56:54 GMT&quot;),&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; },&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &apos;$set&apos;: {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; name: &apos;Zildjian&apos;,&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; },&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;})&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Th&#1077; `&lt;tt&gt;$setOnUpdate&lt;/tt&gt;` field means what data needs to be updated along with the data updated by the `&lt;tt&gt;$set&lt;/tt&gt;` field.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;`&lt;tt&gt;matchedCount&lt;/tt&gt;`&#160; = number of matched docs&lt;/li&gt;
	&lt;li&gt;`&lt;tt&gt;modifiedCount&lt;/tt&gt;` = number of modified only by the `&lt;tt&gt;$set&lt;/tt&gt;` field&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I think this will add flexibility when working with the database and, at the same time, it will not break the existing code.&lt;/p&gt;

&lt;p&gt;Please see discussions with some examples:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/Automattic/mongoose/issues/6861&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;`nModified: 1` returned by `.update()` when $addToSet makes no modification&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;[updateMany().nModified does not work correctly with timestamps
&lt;div class=&apos;table-wrap&apos;&gt;
&lt;table class=&apos;confluenceTable&apos;&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td class=&apos;confluenceTd&apos;&gt;https://github.com/Automattic/mongoose/issues/9452]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/typegoose/typegoose/issues/388&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;updateMany() returns wrong nModified value&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;hr /&gt;
&lt;p&gt;With best regards,&lt;br/&gt;
Vladimir Revenko&lt;/p&gt;

&lt;p&gt;Email: &lt;span class=&quot;nobr&quot;&gt;&lt;a href=&quot;mailto:vova@revenko.org&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;vova@revenko.org&lt;sup&gt;&lt;img class=&quot;rendericon&quot; src=&quot;https://jira.mongodb.org/images/icons/mail_small.gif&quot; height=&quot;12&quot; width=&quot;13&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/sup&gt;&lt;/a&gt;&lt;/span&gt;&lt;br/&gt;
Telegram: &lt;a href=&quot;https://t.me/vovarevenko&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;@vovarevenko&lt;/a&gt;&lt;/p&gt;</description>
                <environment></environment>
        <key id="1494724">SERVER-51208</key>
            <summary>New field `$setOnUpdate` will solve some problems</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="eric.sedor@mongodb.com">Eric Sedor</assignee>
                                    <reporter username="vova@revenko.org">Vladimir Revenko</reporter>
                        <labels>
                    </labels>
                <created>Tue, 29 Sep 2020 11:45:58 +0000</created>
                <updated>Tue, 6 Oct 2020 14:01:52 +0000</updated>
                            <resolved>Tue, 6 Oct 2020 14:01:51 +0000</resolved>
                                                                                        <votes>1</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="3427796" author="JIRAUSER1257093" created="Tue, 6 Oct 2020 10:04:43 +0000"  >&lt;p&gt;Thanks for the answer! I have read&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-42084&quot; title=&quot;Easy syntax for $setIfModified behavior&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-42084&quot;&gt;SERVER-42084&lt;/a&gt;, you can close this ticket&#160;&lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/thumbs_up.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                            <comment id="3418881" author="eric.sedor" created="Wed, 30 Sep 2020 16:14:14 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=vova%40revenko.org&quot; class=&quot;user-hover&quot; rel=&quot;vova@revenko.org&quot;&gt;vova@revenko.org&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;We&apos;re going to close this ticket as a duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-42084&quot; title=&quot;Easy syntax for $setIfModified behavior&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-42084&quot;&gt;SERVER-42084&lt;/a&gt;, but appreciate your well-described request. Would you be willing to add your thoughts to that ticket and watch it for updates?&lt;/p&gt;

&lt;p&gt;Note that &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-42084&quot; title=&quot;Easy syntax for $setIfModified behavior&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-42084&quot;&gt;SERVER-42084&lt;/a&gt; also offers a workaround that may be of benefit for Mongoose and MongoDB 4.2+.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
Eric&lt;/p&gt;</comment>
                            <comment id="3416895" author="asya" created="Tue, 29 Sep 2020 18:22:52 +0000"  >&lt;p&gt;This appears to be similar if not identical to &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-42084&quot; title=&quot;Easy syntax for $setIfModified behavior&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-42084&quot;&gt;SERVER-42084&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="835147">SERVER-42084</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="131030">SERVER-13578</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </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>Tue, 29 Sep 2020 18:22:52 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        3 years, 18 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>eric.sedor@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            3 years, 18 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>eric.sedor@mongodb.com</customfieldvalue>
            <customfieldvalue>vova@revenko.org</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hy9bzj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hxvpxr:</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_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[eric.sedor@mongodb.com]]></customfieldvalue>
    

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

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