<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 07:40:35 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>[DOCS-1248] Comment on: &quot;manual/applications/map-reduce.txt&quot;</title>
                <link>https://jira.mongodb.org/browse/DOCS-1248</link>
                <project id="10380" key="DOCS">Documentation</project>
                    <description>&lt;p&gt;I find a strange problem when I use map-reduce,here is the description:&lt;br/&gt;
first I insert data into database like this:&lt;br/&gt;
//insert.js&lt;br/&gt;
for(var i=0;i&amp;lt;5;i++){&lt;br/&gt;
db.RegistRecord.save(&lt;/p&gt;
{&quot;ip&quot;:&quot;11.11.11.11&quot;,&quot;account&quot;:&quot;ongyong&quot;}
&lt;p&gt;);&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;for(var i=0;i&amp;lt;2;i++){&lt;br/&gt;
db.RegistRecord.save(&lt;/p&gt;
{&quot;ip&quot;:&quot;11.11.11.22&quot;,&quot;account&quot;:&quot;ongyong22&quot;}
&lt;p&gt;);&lt;br/&gt;
}&lt;br/&gt;
for(var i=0;i&amp;lt;1;i++){&lt;br/&gt;
db.RegistRecord.save(&lt;/p&gt;
{&quot;ip&quot;:&quot;11.11.11.33&quot;,&quot;account&quot;:&quot;ongyong33&quot;}
&lt;p&gt;);&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;then run map-reduce through a javascript like this:&lt;/p&gt;

&lt;p&gt;//regmp.js&lt;br/&gt;
printjson(&quot;job start&quot;);&lt;br/&gt;
var map = function() {&lt;br/&gt;
  emit(this.ip, &lt;/p&gt;
{value: 1}
&lt;p&gt;);&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;var reduce = function(key, values) {&lt;br/&gt;
  var count = 0;&lt;br/&gt;
  values.forEach(function(v) &lt;/p&gt;
{
	count += v[&apos;value&apos;];
  }
&lt;p&gt;);&lt;br/&gt;
  return &lt;/p&gt;
{count: count }
&lt;p&gt;;&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;var res = db.runCommand(&lt;/p&gt;
{mapreduce:&quot;RegistRecord&quot;,map:map, reduce:reduce, out:&quot;log_results&quot;}
&lt;p&gt;);&lt;br/&gt;
printjson(&quot;job end&quot;)&lt;/p&gt;

&lt;p&gt;Ok,you&apos;ll find the result is no problem and like this:&lt;br/&gt;
/* 0 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;_id&quot; : &quot;11.11.11.11&quot;,&lt;br/&gt;
  &quot;value&quot; : &lt;/p&gt;
{
    &quot;count&quot; : 5.0
  }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;/* 1 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;_id&quot; : &quot;11.11.11.22&quot;,&lt;br/&gt;
  &quot;value&quot; : &lt;/p&gt;
{
    &quot;count&quot; : 2.0
  }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;/* 2 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;_id&quot; : &quot;11.11.11.33&quot;,&lt;br/&gt;
  &quot;value&quot; : &lt;/p&gt;
{
    &quot;value&quot; : 1.0
  }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;but,when the records increase to 2000,strange problem comes:&lt;br/&gt;
insert data first like this :&lt;br/&gt;
//insert.js&lt;br/&gt;
for(var i=0;i&amp;lt;2000;i++){&lt;br/&gt;
db.RegistRecord.save(&lt;/p&gt;
{&quot;ip&quot;:&quot;11.11.11.11&quot;,&quot;account&quot;:&quot;ongyong&quot;}
&lt;p&gt;);&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;for(var i=0;i&amp;lt;2;i++){&lt;br/&gt;
db.RegistRecord.save(&lt;/p&gt;
{&quot;ip&quot;:&quot;11.11.11.22&quot;,&quot;account&quot;:&quot;ongyong22&quot;}
&lt;p&gt;);&lt;br/&gt;
}&lt;br/&gt;
for(var i=0;i&amp;lt;1;i++){&lt;br/&gt;
db.RegistRecord.save(&lt;/p&gt;
{&quot;ip&quot;:&quot;11.11.11.33&quot;,&quot;account&quot;:&quot;ongyong33&quot;}
&lt;p&gt;);&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;run the same script and the result is like this :&lt;br/&gt;
/* 0 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;_id&quot; : &quot;11.11.11.11&quot;,&lt;br/&gt;
  &quot;value&quot; : &lt;/p&gt;
{
   &quot;count&quot; : NaN
  }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;/* 1 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;_id&quot; : &quot;11.11.11.22&quot;,&lt;br/&gt;
  &quot;value&quot; : &lt;/p&gt;
{
    &quot;count&quot; : 2.0
  }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;/* 2 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;_id&quot; : &quot;11.11.11.33&quot;,&lt;br/&gt;
  &quot;value&quot; : &lt;/p&gt;
{
    &quot;value&quot; : 1.0
  }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;see the fird record ? &quot;NaN&quot;??&lt;br/&gt;
And I also find that the data reduce function received is strange:&lt;/p&gt;

&lt;p&gt;/* 0 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;_id&quot; : &quot;11.11.11.22&quot;,&lt;br/&gt;
  &quot;value&quot; : {&lt;br/&gt;
    &quot;count&quot; : [&lt;/p&gt;
{
        &quot;value&quot; : 1.0
      }
&lt;p&gt;, &lt;/p&gt;
{
        &quot;value&quot; : 1.0
      }
&lt;p&gt;]&lt;br/&gt;
  }&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;/* 1 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;_id&quot; : &quot;11.11.11.33&quot;,&lt;br/&gt;
  &quot;value&quot; : &lt;/p&gt;
{
    &quot;value&quot; : 1.0
  }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;/* 2 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;_id&quot; : &quot;11.11.11.11&quot;,&lt;br/&gt;
  &quot;value&quot; : {&lt;br/&gt;
   &quot;count&quot; : [{&lt;br/&gt;
        &quot;count&quot; : [&lt;/p&gt;
{
            &quot;value&quot; : 1.0
          }
&lt;p&gt;, &lt;/p&gt;
{
            &quot;value&quot; : 1.0
          }
&lt;p&gt;, &lt;/p&gt;
{
            &quot;value&quot; : 1.0
          }
&lt;p&gt;,&lt;br/&gt;
			&#12290;&#12290;&#12290;&#12290;&lt;/p&gt;

&lt;p&gt;Sorry for my poor English...&lt;br/&gt;
hope for your response!&lt;/p&gt;


</description>
                <environment>redhat linux 64bit&lt;br/&gt;
mongodb-linux-i686-2.2.3&lt;br/&gt;
&lt;br/&gt;
*Location*: &lt;a href=&quot;http://docs.mongodb.org/manual/applications/map-reduce/&quot;&gt;http://docs.mongodb.org/manual/applications/map-reduce/&lt;/a&gt;&lt;br/&gt;
*User-Agent*: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11&lt;br/&gt;
*Referrer*: &lt;a href=&quot;http://www.cnblogs.com/daizhj/archive/2010/06/10/1755761.html&quot;&gt;http://www.cnblogs.com/daizhj/archive/2010/06/10/1755761.html&lt;/a&gt;&lt;br/&gt;
*Screen Resolution*: 1366 x 768&lt;br/&gt;
*repo*: docs&lt;br/&gt;
*source*: applications/map-reduce&lt;br/&gt;
</environment>
        <key id="68665">DOCS-1248</key>
            <summary>Comment on: &quot;manual/applications/map-reduce.txt&quot;</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="kay.kim@mongodb.com">Kay Kim</assignee>
                                    <reporter username="auto">auto</reporter>
                        <labels>
                            <label>collector-298ba4e7</label>
                    </labels>
                <created>Sat, 16 Mar 2013 15:47:09 +0000</created>
                <updated>Fri, 3 Nov 2017 11:24:20 +0000</updated>
                            <resolved>Tue, 2 Apr 2013 23:15:36 +0000</resolved>
                                                                        <due></due>
                            <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="304647" author="kay.kim@10gen.com" created="Tue, 2 Apr 2013 23:15:36 +0000"  >&lt;p&gt;Thank you so much for your comment.&lt;/p&gt;

&lt;p&gt;With map-reduce, the reduce function must have the following property:&lt;/p&gt;

&lt;p&gt;      reduce( key, [ reduce(key, valuesArray) ] ) == reduce( key, valuesArray )&lt;/p&gt;

&lt;p&gt;Your  reduce function does not share the property:&lt;/p&gt;

&lt;p&gt;      var reduce = function(key, values) {&lt;br/&gt;
           var count = 0;&lt;br/&gt;
           values.forEach(function(v) &lt;/p&gt;
{ count += v[&apos;value&apos;]; }
&lt;p&gt;);&lt;br/&gt;
           return &lt;/p&gt;
{count: count }
&lt;p&gt;;&lt;br/&gt;
      }&lt;/p&gt;


&lt;p&gt;that is  &lt;/p&gt;

&lt;p&gt;      reduce(&quot;11.11.11.11&quot;, [ reduce(&quot;11.11.11.11&quot;, [ &lt;/p&gt;
{ value: 1 }
&lt;p&gt; ] ) ] ) does not equal reduce( &quot;11.11.11.11&quot;, [ &lt;/p&gt;
{value: 1}
&lt;p&gt; ] )&lt;/p&gt;

&lt;p&gt;If you try:&lt;/p&gt;

&lt;p&gt;var map = function() {&lt;br/&gt;
emit(this.ip, 1 );&lt;br/&gt;
}&lt;/p&gt;


&lt;p&gt;var reduce = function(key, values) {&lt;br/&gt;
 return Array.sum(values);&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;this should work for you.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;http://docs.mongodb.org/manual/reference/method/db.collection.mapReduce&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/manual/reference/method/db.collection.mapReduce&lt;/a&gt; page lists  (around the middle of the page) the requirements for the map and reduce functions&lt;/p&gt;

&lt;p&gt;Hope this answers your question.&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>1.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 26 Mar 2013 02:30:39 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            10 years, 46 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>auto</customfieldvalue>
            <customfieldvalue>kay.kim@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrrzw7:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>46425</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrzkun:</customfieldvalue>

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