<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 04:41:45 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-36009] $min, $max field update operators from another field</title>
                <link>https://jira.mongodb.org/browse/SERVER-36009</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I&apos;ve pass the last hours searching for a realiable way to keep a minimun field value up to date.&lt;/p&gt;

&lt;p&gt;For example, you have:&lt;/p&gt;

{ minAll: [1,2,3,4], min: 1 }

&lt;p&gt;For this current case, Its possible to have an index on &apos;minAll&apos; and query a &apos;$min&apos; operator under aggregate, but (1) the index will grow more so Its more memory expensive and (2) having it precalculated in another field you can get some performance improvements.&lt;/p&gt;

&lt;p&gt;The basic idea is:&lt;/p&gt;

&lt;p&gt;&#160; &#160; update({&quot;_id&quot;:&quot;test&quot;},&lt;/p&gt;
{
&#160; &#160; &#160; &#160; &quot;$pull&quot;:\{&quot;minAll&quot;:1}
&lt;p&gt;,&lt;br/&gt;
&#160; &#160; &#160; &#160; &quot;$set&quot;:{&quot;min&quot;:{&quot;$min&quot;:&quot;$minAll&quot;}} //should be 2 now&lt;br/&gt;
&#160; &#160; });&lt;/p&gt;

&lt;p&gt;When you remove or add an element, would be great to be able to update another field based on the new collection this field currently has. Or simply re-index all documents again:&lt;/p&gt;

&lt;p&gt;&#160; &#160; update({},{&lt;br/&gt;
&#160; &#160; &#160; &#160; &quot;$set&quot;:{&quot;min&quot;:{&quot;$min&quot;:&quot;$minAll&quot;}}&lt;br/&gt;
&#160; &#160; });&lt;/p&gt;

&lt;p&gt;Currently you can do it this way:&lt;/p&gt;

&lt;p&gt;&#160; &#160;var elem = findAndModify({&quot;_id&quot;:&quot;test&quot;},{&quot;$pull&quot;:{&quot;minAll&quot;:1}});&lt;br/&gt;
&#160; &#160;var nmin = Math.min(elem.minAll);&lt;br/&gt;
&#160; &#160;/* Posible other delays */&lt;br/&gt;
&#160; &#160;findAndModify({&quot;_id&quot;:&quot;test&quot;},{&quot;$set&quot;:{&quot;min&quot;:nmin}});&lt;/p&gt;

&lt;p&gt;I have no problem doing 2 updates, the main problem from my pov is that this is not atomic, so if you have bad luck, under heavy load, in the microseconds you use to calculate &apos;nmin&apos; the &apos;minAll&apos; field could have changed and updated &apos;min&apos; in parallel, so you are basically overwriting the field with old value.&lt;/p&gt;

&lt;p&gt;This is similar to &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1534?focusedCommentId=322573&amp;amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-322573&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/SERVER-1534?focusedCommentId=322573&amp;amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-322573&lt;/a&gt;&#160;. With current behaviour you can easily keep up to date the max value of an array field modified by $push, but you have no chance to update max if you use a $pull and removed the top value.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</description>
                <environment></environment>
        <key id="568977">SERVER-36009</key>
            <summary>$min, $max field update operators from another field</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="4">Incomplete</resolution>
                                        <assignee username="asya.kamsky@mongodb.com">Asya Kamsky</assignee>
                                    <reporter username="sombra2eternity@gmail.com">Marcos Fern&#225;ndex</reporter>
                        <labels>
                    </labels>
                <created>Sun, 8 Jul 2018 00:01:15 +0000</created>
                <updated>Tue, 16 Nov 2021 16:50:59 +0000</updated>
                            <resolved>Thu, 16 Aug 2018 22:47:46 +0000</resolved>
                                                                    <component>Querying</component>
                                        <votes>0</votes>
                                    <watches>10</watches>
                                                                                                                <comments>
                            <comment id="1985872" author="sombra2eternity@gmail.com" created="Sun, 26 Aug 2018 12:09:28 +0000"  >&lt;p&gt;Fair enough&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</comment>
                            <comment id="1985843" author="asya" created="Sun, 26 Aug 2018 05:45:03 +0000"  >&lt;p&gt;&amp;gt;  javascript fix only&lt;/p&gt;

&lt;p&gt;We do not plan to implement this in any driver language - this would use existing server operators/expressions exactly as you suggest in the comment.&lt;/p&gt;</comment>
                            <comment id="1978249" author="sombra2eternity@gmail.com" created="Thu, 16 Aug 2018 23:19:34 +0000"  >&lt;p&gt;Hi, sorry, missed last message.&lt;/p&gt;

&lt;p&gt;I&apos;m not sure if this will be addressed completely by&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1765&quot; title=&quot;self referential updates? WAS: allow access to old row value during update&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1765&quot;&gt;&lt;del&gt;SERVER-1765&lt;/del&gt;&lt;/a&gt;.&lt;br/&gt;
 In the description of that report there is the next example:&lt;/p&gt;

&lt;p&gt;{ $set : { &quot;priority&quot; : min(old.priority, 3) }}&lt;/p&gt;

&lt;p&gt;Yes, a similar approach could workaround this problem, but I think it&apos;s a javascript fix only. I use mongodb in several languages but mainly in php, there is no way I could think to translate that to a findAndModify or update valid query in php for example, so could cause more headaches to port.&lt;/p&gt;

&lt;p&gt;My proposal was more simple than that. Mongo already gives you min value of an array field when you use $min under an aggregate, so there is a behaviour that everybody knows. I just comment on extending this same behaviour to the findAndModify/update $set query, just for language consistence:&lt;/p&gt;

&lt;p&gt;{$set:{&quot;newfield&quot;:{$min:&quot;$oldfield&quot;}}}&lt;/p&gt;

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

&lt;p&gt;Maybe with&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1765&quot; title=&quot;self referential updates? WAS: allow access to old row value during update&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1765&quot;&gt;&lt;del&gt;SERVER-1765&lt;/del&gt;&lt;/a&gt; you could make something like:&lt;/p&gt;

&lt;p&gt;{$set:{&quot;newfield&quot;:{$min:&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;$oldfield&amp;quot;,3&amp;#93;&lt;/span&gt;}}}&lt;/p&gt;

&lt;p&gt;Using mongo native $min instead of Math.min could be ok, but imho it&apos;s incomplete, just because aggregate allows the 2 operations. I opened this bug with lowest priority because it&apos;s not a blocker or something important, just to remind the mongo guys that the $min and $max operators should has its place in findAndModify/update in the end and should behave like they do on aggregate.&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</comment>
                            <comment id="1978218" author="asya" created="Thu, 16 Aug 2018 22:47:46 +0000"  >&lt;p&gt;We think this would be addressed by &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1765&quot; title=&quot;self referential updates? WAS: allow access to old row value during update&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1765&quot;&gt;&lt;del&gt;SERVER-1765&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1948362" author="ramon.fernandez" created="Mon, 16 Jul 2018 18:04:46 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=sombra2eternity&quot; class=&quot;user-hover&quot; rel=&quot;sombra2eternity&quot;&gt;sombra2eternity&lt;/a&gt;, would something like &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1765&quot; title=&quot;self referential updates? WAS: allow access to old row value during update&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1765&quot;&gt;&lt;del&gt;SERVER-1765&lt;/del&gt;&lt;/a&gt; address your needs?&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_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 9 Jul 2018 05:42:05 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            5 years, 24 weeks, 3 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>sombra2eternity@gmail.com</customfieldvalue>
            <customfieldvalue>ramon.fernandez@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hu27cv:</customfieldvalue>

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

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

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