<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:07:09 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-4847] Wrong key returned from map/reduce</title>
                <link>https://jira.mongodb.org/browse/SERVER-4847</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;It looks like there&apos;s an optimization for map reduce jobs that can result in the wrong key name being returned if there is only a single tuple to process.  Notice how the keys for groups 1 and 5 are returned as &quot;thetot&quot; instead of &quot;tot&quot; in the job below.&lt;/p&gt;

&lt;p&gt;I believe this is caused by line 103/124 of db/commands/mr.cpp.  The workaround appears easy enough but I thought I&apos;d report it.&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;


&lt;p&gt;&amp;gt; db.goo.save(&lt;/p&gt;
{group:1, amt:5}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:2, amt:3}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:2, amt:15}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:3, amt:1}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:3, amt:2}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:3, amt:9}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:4, amt:1}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:4, amt:3}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:4, amt:10}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:4, amt:12}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; db.goo.save(&lt;/p&gt;
{group:5, amt:2}
&lt;p&gt;);&lt;br/&gt;
&amp;gt; &lt;br/&gt;
&amp;gt; map = function(){ emit( this.group, &lt;/p&gt;
{ cnt:1, thetot:this.amt }
&lt;p&gt;); }&lt;br/&gt;
function () {&lt;br/&gt;
    emit(this.group, &lt;/p&gt;
{cnt:1, thetot:this.amt}
&lt;p&gt;);&lt;br/&gt;
}&lt;br/&gt;
&amp;gt; &lt;br/&gt;
&amp;gt; reduce = function(k, v){&lt;br/&gt;
...     var r = &lt;/p&gt;
{ cnt:0, tot:0 }
&lt;p&gt;;&lt;br/&gt;
...     v.forEach(function(v)&lt;/p&gt;
{ 
...         r.cnt += v.cnt;
...         r.tot += v.thetot ;
...     }
&lt;p&gt;)  &lt;br/&gt;
...     return r;&lt;br/&gt;
... }   &lt;br/&gt;
function (k, v) {&lt;br/&gt;
    var r = &lt;/p&gt;
{cnt:0, tot:0}
&lt;p&gt;;&lt;br/&gt;
    v.forEach(function (v) &lt;/p&gt;
{r.cnt += v.cnt;r.tot += v.thetot;}
&lt;p&gt;);&lt;br/&gt;
    return r;&lt;br/&gt;
}&lt;br/&gt;
&amp;gt; &lt;br/&gt;
&amp;gt; db.goo.mapReduce( map, reduce, { out:&lt;/p&gt;
{inline:1}
&lt;p&gt; });&lt;br/&gt;
{&lt;br/&gt;
	&quot;results&quot; : [&lt;br/&gt;
		{&lt;br/&gt;
			&quot;_id&quot; : 1,&lt;br/&gt;
			&quot;value&quot; : &lt;/p&gt;
{
				&quot;cnt&quot; : 1,
				&quot;thetot&quot; : 5
			}
&lt;p&gt;		},&lt;br/&gt;
		{&lt;br/&gt;
			&quot;_id&quot; : 2,&lt;br/&gt;
			&quot;value&quot; : &lt;/p&gt;
{
				&quot;cnt&quot; : 2,
				&quot;tot&quot; : 18
			}
&lt;p&gt;		},&lt;br/&gt;
		{&lt;br/&gt;
			&quot;_id&quot; : 3,&lt;br/&gt;
			&quot;value&quot; : &lt;/p&gt;
{
				&quot;cnt&quot; : 3,
				&quot;tot&quot; : 12
			}
&lt;p&gt;		},&lt;br/&gt;
		{&lt;br/&gt;
			&quot;_id&quot; : 4,&lt;br/&gt;
			&quot;value&quot; : &lt;/p&gt;
{
				&quot;cnt&quot; : 4,
				&quot;tot&quot; : 26
			}
&lt;p&gt;		},&lt;br/&gt;
		{&lt;br/&gt;
			&quot;_id&quot; : 5,&lt;br/&gt;
			&quot;value&quot; : &lt;/p&gt;
{
				&quot;cnt&quot; : 1,
				&quot;thetot&quot; : 2
			}
&lt;p&gt;		}&lt;br/&gt;
	],&lt;br/&gt;
	&quot;timeMillis&quot; : 1,&lt;br/&gt;
	&quot;counts&quot; : &lt;/p&gt;
{
		&quot;input&quot; : 11,
		&quot;emit&quot; : 11,
		&quot;output&quot; : 5
	}
&lt;p&gt;,&lt;br/&gt;
	&quot;ok&quot; : 1,&lt;br/&gt;
}&lt;/p&gt;</description>
                <environment></environment>
        <key id="29679">SERVER-4847</key>
            <summary>Wrong key returned from map/reduce</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="5" iconUrl="https://jira.mongodb.org/images/icons/priorities/trivial.svg">Trivial - P5</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="jlee">Jeff lee</reporter>
                        <labels>
                    </labels>
                <created>Thu, 2 Feb 2012 02:13:50 +0000</created>
                <updated>Wed, 29 Feb 2012 03:53:57 +0000</updated>
                            <resolved>Thu, 2 Feb 2012 06:06:18 +0000</resolved>
                                    <version>2.0.2</version>
                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="84509" author="jlee" created="Thu, 2 Feb 2012 14:27:40 +0000"  >&lt;p&gt;Heh...I guess it helps to fully read the docs.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</comment>
                            <comment id="84367" author="eliot" created="Thu, 2 Feb 2012 06:06:18 +0000"  >&lt;p&gt;This is correct behavior.&lt;/p&gt;

&lt;p&gt;What you emit and what reduce returns has to be the same format as things get re-reduced.&lt;/p&gt;

&lt;p&gt;So its possible things won&apos;t get reduced at all if there is only 1 entry for a key.&lt;/p&gt;

&lt;p&gt;You can use finalize to do final processing per key.&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>2.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Thu, 2 Feb 2012 06:06:18 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        12 years, 2 weeks, 6 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>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, 2 weeks, 6 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="10026"><![CDATA[ALL]]></customfieldvalue>

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

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

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

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