<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:02:50 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-3352] Map-Reduce JS increment operators (++, +=1) do not work</title>
                <link>https://jira.mongodb.org/browse/SERVER-3352</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;In my reduce function, I can only increment a counter with&lt;/p&gt;

&lt;p&gt;  result.counter += value.counter&lt;/p&gt;

&lt;p&gt;These alternatives do not work:&lt;/p&gt;

&lt;p&gt;  result.counter++&lt;br/&gt;
  result.counter += 1&lt;br/&gt;
  result.counter = result.counter + 1&lt;/p&gt;

&lt;p&gt;Full code:&lt;/p&gt;

&lt;p&gt;  def total (query = nil)&lt;br/&gt;
    map_fn = &quot;function() {&lt;br/&gt;
      values = {};&lt;br/&gt;
      values.displays = 1;&lt;br/&gt;
      values.attempts = this.disposition != &apos;16&apos; ? 1 : 0;&lt;br/&gt;
      values.contacts = this.disposition == &apos;1&apos; ? 1 : 0;&lt;br/&gt;
      emit(1,values);&lt;br/&gt;
    }&quot;&lt;/p&gt;

&lt;p&gt;    reduce_fn = &quot;function(key, values) {&lt;br/&gt;
      var total = &lt;/p&gt;
{displays: 0, attempts: 0, contacts: 0}
&lt;p&gt;;&lt;br/&gt;
      values.forEach( function(value) &lt;/p&gt;
{
//      total.displays++;                  // FAIL
//      total.displays += 1;               // FAIL
//        total.displays = total.displays+1;    // FAIL
        total.displays += value.displays;  // SUCCESS
        total.attempts += value.attempts;
        total.contacts += value.contacts;        
      }
&lt;p&gt;);&lt;br/&gt;
      return total;&lt;br/&gt;
    }&quot;&lt;/p&gt;

&lt;p&gt;    results_collection = Contact.collection.map_reduce(map_fn, reduce_fn, {:out =&amp;gt; {:inline =&amp;gt; 1}, :raw =&amp;gt; true, :query =&amp;gt; query})&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;results&amp;#39;&amp;#93;&lt;/span&gt;&lt;br/&gt;
    results_collection.present? ? results_collection.first&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;value&amp;#39;&amp;#93;&lt;/span&gt; : []&lt;/p&gt;

&lt;p&gt;  end &lt;/p&gt;</description>
                <environment>osx snow leopard, ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]&lt;br/&gt;
&amp;nbsp;</environment>
        <key id="18916">SERVER-3352</key>
            <summary>Map-Reduce JS increment operators (++, +=1) do not work</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="9">Done</resolution>
                                        <assignee username="antoine">Antoine Girbal</assignee>
                                    <reporter username="dogbert2521">Pete Campbell</reporter>
                        <labels>
                            <label>query</label>
                    </labels>
                <created>Thu, 30 Jun 2011 21:45:45 +0000</created>
                <updated>Tue, 12 Jul 2016 00:17:19 +0000</updated>
                            <resolved>Wed, 12 Oct 2011 03:41:56 +0000</resolved>
                                    <version>1.8.2</version>
                                                    <component>JavaScript</component>
                    <component>MapReduce</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="101801" author="azat" created="Fri, 23 Mar 2012 12:52:23 +0000"  >&lt;p&gt;Here it is #5379&lt;/p&gt;</comment>
                            <comment id="101779" author="azat" created="Fri, 23 Mar 2012 10:37:23 +0000"  >&lt;p&gt;I have the same issue, must I create a new ticket, or you reopen this, and I post some usefull information?&lt;/p&gt;</comment>
                            <comment id="59955" author="antoine" created="Wed, 12 Oct 2011 03:41:56 +0000"  >&lt;p&gt;This has been verified to work with mongo 2.0 and master branch.&lt;br/&gt;
The following code properly increments values&lt;br/&gt;
foo.foo / M/R: { &quot;mapreduce&quot; : &quot;foo&quot; , &quot;map&quot; : &quot;function(){ emit(this.n, &lt;/p&gt;
{count:1}
&lt;p&gt;); }&quot; , &quot;reduce&quot; : &quot;function(key, values) { total = &lt;/p&gt;
{count: 0}
&lt;p&gt;; for (var i = 0; i &amp;lt; values.length; ++i) &lt;/p&gt;
{ total.count++; }
&lt;p&gt;; return total; }&quot; , &quot;out&quot; : { &quot;replace&quot; : &quot;mrtest&quot;}}&lt;/p&gt;

&lt;p&gt;Pete, marking as resolved, if you have further clues on the issue please reopen.&lt;/p&gt;</comment>
                            <comment id="40728" author="antoine" created="Tue, 5 Jul 2011 21:48:49 +0000"  >&lt;p&gt;what do you mean by fails?&lt;br/&gt;
do you get a different result that you expect, or is it stuck at 0?&lt;br/&gt;
are you using the standard 1.8.2 (with spidermonkey js engine)?&lt;br/&gt;
The operator is working for my tests.&lt;/p&gt;

&lt;p&gt;Note that in any case it is usually not going to be consistent to do &quot;+ constant&quot; in a reduce.&lt;br/&gt;
The reduce may be called many times for the same key, and must be idempotent.&lt;br/&gt;
So here the value you get may be higher than you expect.&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>4.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 5 Jul 2011 21:48:49 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            11 years, 47 weeks, 5 days 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="10021"><![CDATA[OS X]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>antoine</customfieldvalue>
            <customfieldvalue>azat</customfieldvalue>
            <customfieldvalue>dogbert2521</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrowp3:</customfieldvalue>

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

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

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