<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:58:03 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-1787] incorrect results: map/reduce + query + index on an array</title>
                <link>https://jira.mongodb.org/browse/SERVER-1787</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I used the following collection and funtions (based on &quot;MapReduce&lt;br/&gt;
Example 2&quot; &lt;a href=&quot;http://www.mongodb.org/display/DOCS/MapReduce&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.mongodb.org/display/DOCS/MapReduce&lt;/a&gt; and&lt;br/&gt;
&quot;Multikeys (Indexing Values in an Array)&quot;&lt;br/&gt;
&lt;a href=&quot;http://www.mongodb.org/display/DOCS/Full+Text+Search+in+Mongo#FullTex&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.mongodb.org/display/DOCS/Full+Text+Search+in+Mongo#FullTex&lt;/a&gt;...).&lt;/p&gt;

&lt;p&gt;-----------------------------------&lt;br/&gt;
db.things.drop();&lt;/p&gt;

&lt;p&gt;db.things.ensureIndex(&lt;/p&gt;
{name:1, tags:1}
&lt;p&gt;);&lt;/p&gt;

&lt;p&gt;db.things.insert( &lt;/p&gt;
{ _id : 1, name : &apos;name1&apos;, tags : [&apos;dog&apos;, &apos;cat&apos;] }
&lt;p&gt; );&lt;br/&gt;
db.things.insert( &lt;/p&gt;
{ _id : 2, name : &apos;name2&apos;, tags : [&apos;cat&apos;] }
&lt;p&gt; );&lt;br/&gt;
db.things.insert( &lt;/p&gt;
{ _id : 3, name : &apos;name3&apos;, tags : [&apos;mouse&apos;, &apos;cat&apos;, &apos;dog&apos;] }
&lt;p&gt; );&lt;br/&gt;
db.things.insert( &lt;/p&gt;
{ _id : 4, name : &apos;name4&apos;, tags : []  }
&lt;p&gt; );&lt;/p&gt;

&lt;p&gt;m = function(){&lt;br/&gt;
  this.tags.forEach(&lt;br/&gt;
      function(z){ emit( z , &lt;/p&gt;
{ count : 1 }
&lt;p&gt; ); } );&lt;br/&gt;
};&lt;/p&gt;

&lt;p&gt;r = function( key , values ){&lt;br/&gt;
   var total = 0;&lt;br/&gt;
   for ( var i=0; i&amp;lt;values.length; i++ )&lt;br/&gt;
      total += values&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;.count;&lt;br/&gt;
   return &lt;/p&gt;
{ count : total }
&lt;p&gt;;&lt;br/&gt;
};&lt;/p&gt;

&lt;p&gt;res = db.runCommand(&lt;/p&gt;
{ mapreduce : &apos;things&apos;, map : m, reduce : r }
&lt;p&gt;);&lt;/p&gt;

&lt;p&gt;db&lt;span class=&quot;error&quot;&gt;&amp;#91;res.result&amp;#93;&lt;/span&gt;.find();&lt;/p&gt;

&lt;p&gt;-----------------------------------&lt;/p&gt;

&lt;p&gt;Expected result:&lt;br/&gt;
  dog : 3&lt;br/&gt;
  cat: 2&lt;br/&gt;
  mouse : 1&lt;/p&gt;

&lt;p&gt;Function result:&lt;br/&gt;
  { &quot;_id&quot; : &quot;cat&quot;, &quot;value&quot; : &lt;/p&gt;
{ &quot;count&quot; : 3 }
&lt;p&gt; }&lt;br/&gt;
  { &quot;_id&quot; : &quot;dog&quot;, &quot;value&quot; : &lt;/p&gt;
{ &quot;count&quot; : 2 }
&lt;p&gt; }&lt;br/&gt;
  { &quot;_id&quot; : &quot;mouse&quot;, &quot;value&quot; : &lt;/p&gt;
{ &quot;count&quot; : 1 }
&lt;p&gt; }&lt;/p&gt;

&lt;p&gt;OK!&lt;/p&gt;

&lt;p&gt;Now the same with a query: count only tags in doctumenmts with&lt;br/&gt;
name=&apos;name1&apos;:&lt;/p&gt;

&lt;p&gt;-----------------------------------&lt;/p&gt;

&lt;p&gt;res = db.runCommand({ mapreduce : &apos;things&apos;, map : m, reduce : r, query: &lt;/p&gt;
{name : &apos;name1&apos;}
&lt;p&gt; });&lt;/p&gt;

&lt;p&gt;db&lt;span class=&quot;error&quot;&gt;&amp;#91;res.result&amp;#93;&lt;/span&gt;.find();&lt;/p&gt;

&lt;p&gt;-----------------------------------&lt;/p&gt;

&lt;p&gt;Expected result:&lt;br/&gt;
  dog : 1&lt;br/&gt;
  cat: 1&lt;/p&gt;

&lt;p&gt;Function result:&lt;br/&gt;
  { &quot;_id&quot; : &quot;cat&quot;, &quot;value&quot; : &lt;/p&gt;
{ &quot;count&quot; : 2 }
&lt;p&gt; }&lt;br/&gt;
  { &quot;_id&quot; : &quot;dog&quot;, &quot;value&quot; : &lt;/p&gt;
{ &quot;count&quot; : 2 }
&lt;p&gt; }&lt;/p&gt;

&lt;p&gt;Why that????&lt;/p&gt;

&lt;p&gt;&quot;count&quot; always contains the total number of elements in the array&lt;br/&gt;
&apos;tags&apos;. So with &quot;name : &apos;name3&apos;&quot; the result is:&lt;br/&gt;
  { &quot;_id&quot; : &quot;cat&quot;, &quot;value&quot; : &lt;/p&gt;
{ &quot;count&quot; : 3 }
&lt;p&gt; }&lt;br/&gt;
  { &quot;_id&quot; : &quot;dog&quot;, &quot;value&quot; : &lt;/p&gt;
{ &quot;count&quot; : 3 }
&lt;p&gt; }&lt;br/&gt;
  { &quot;_id&quot; : &quot;mouse&quot;, &quot;value&quot; : &lt;/p&gt;
{ &quot;count&quot; : 3 }
&lt;p&gt; }&lt;/p&gt;

&lt;p&gt;The reduce-function is called once for EACH element of the tags-array&lt;br/&gt;
for the SAME tag (tag=key).&lt;/p&gt;

&lt;p&gt;If I don&apos;t create the index &quot;db.things.ensureIndex(&lt;/p&gt;
{name:1, tags:1}
&lt;p&gt;);&quot;&lt;br/&gt;
it works correct. &lt;/p&gt;

&lt;p&gt;Ulrich&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/1f24161d3d1daf01&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/1f24161d3d1daf01&lt;/a&gt;&lt;/p&gt;</description>
                <environment>Windows 7 + mongodb 1.6.2&lt;br/&gt;
and&lt;br/&gt;
Linux + mongodb 1.6.2</environment>
        <key id="13083">SERVER-1787</key>
            <summary>incorrect results: map/reduce + query + index on an array</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="eliot">Eliot Horowitz</assignee>
                                    <reporter username="ua">Ulrich Ahrendt</reporter>
                        <labels>
                    </labels>
                <created>Mon, 13 Sep 2010 19:02:20 +0000</created>
                <updated>Tue, 12 Jul 2016 00:19:00 +0000</updated>
                            <resolved>Sun, 16 Jan 2011 06:22:13 +0000</resolved>
                                                    <fixVersion>1.7.5</fixVersion>
                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="22404" author="auto" created="Sun, 16 Jan 2011 06:22:20 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;erh&apos;, u&apos;name&apos;: u&apos;Eliot Horowitz&apos;, u&apos;email&apos;: u&apos;eliot@10gen.com&apos;}
&lt;p&gt;Message: some mr tests for &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1787&quot; title=&quot;incorrect results: map/reduce + query + index on an array&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1787&quot;&gt;&lt;del&gt;SERVER-1787&lt;/del&gt;&lt;/a&gt; &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2272&quot; title=&quot;Reducing M/R output into a new collection fails&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2272&quot;&gt;&lt;del&gt;SERVER-2272&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/ba78158d2f93394032daa2890e29777b29bf3192&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/ba78158d2f93394032daa2890e29777b29bf3192&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="22403" author="eliot" created="Sun, 16 Jan 2011 06:22:13 +0000"  >&lt;p&gt;was actually fixed earler, but not sure exactly when&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>Sun, 16 Jan 2011 06:22:13 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            13 years, 5 weeks, 3 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>auto</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>ua</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpf5r:</customfieldvalue>

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

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

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