<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:00:41 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-2620] Multi-key indexes on arrays of object with more than one key cause queries to behave like $elemMatch by default.</title>
                <link>https://jira.mongodb.org/browse/SERVER-2620</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Attempting to index and query a set of dynamic attributes, I seem to have encountered a bug.&lt;/p&gt;

&lt;p&gt;&amp;gt; db.foo.save({attrs: [&lt;/p&gt;
{n: &quot;low&quot;, v: 100}
&lt;p&gt;, &lt;/p&gt;
{n: &quot;high&quot;, v: 100}
&lt;p&gt;]})&lt;br/&gt;
&amp;gt; db.foo.save({attrs: [&lt;/p&gt;
{n: &quot;low&quot;, v: 200}
&lt;p&gt;, &lt;/p&gt;
{n: &quot;high&quot;, v: 500}
&lt;p&gt;]})&lt;br/&gt;
&amp;gt; db.foo.find(&lt;/p&gt;
{&quot;attrs.n&quot;: &quot;low&quot;, &quot;attrs.v&quot;: 500}
&lt;p&gt;)&lt;br/&gt;
{ &quot;_id&quot; : ObjectId(&quot;4d66b232d6eb5559fa645ce2&quot;), &quot;attrs&quot; : [ &lt;/p&gt;
{ &quot;n&quot; : &quot;low&quot;, &quot;v&quot; : 200 }
&lt;p&gt;, &lt;/p&gt;
{ &quot;n&quot; : &quot;high&quot;, &quot;v&quot; : 500 }
&lt;p&gt; ] }&lt;/p&gt;

&lt;p&gt;Now we add an index, and this returns nothing:&lt;/p&gt;

&lt;p&gt;&amp;gt; db.foo.ensureIndex(&lt;/p&gt;
{&quot;attrs.n&quot;: 1, &quot;attrs.v&quot;: 1}
&lt;p&gt;)&lt;br/&gt;
&amp;gt; db.foo.find(&lt;/p&gt;
{&quot;attrs.n&quot;: &quot;low&quot;, &quot;attrs.v&quot;: 500}
&lt;p&gt;)&lt;br/&gt;
(Returns nothing)&lt;/p&gt;

&lt;p&gt;Shouldn&apos;t the behavior be the same with the index in place?&lt;/p&gt;

&lt;p&gt;However. A query matching a complete object with the document work with the index:&lt;br/&gt;
&amp;gt; db.foo.find(&lt;/p&gt;
{&quot;attrs.n&quot;: &quot;low&quot;, &quot;attrs.v&quot;: 200}
&lt;p&gt;)&lt;br/&gt;
{ &quot;_id&quot; : ObjectId(&quot;4d66b232d6eb5559fa645ce2&quot;), &quot;attrs&quot; : [ &lt;/p&gt;
{ &quot;n&quot; : &quot;low&quot;, &quot;v&quot; : 200 }
&lt;p&gt;, &lt;/p&gt;
{ &quot;n&quot; : &quot;high&quot;, &quot;v&quot; : 500 }
&lt;p&gt; ] }&lt;/p&gt;

&lt;p&gt;And seems to be doing the equivalent of an $elemMatch:&lt;br/&gt;
&amp;gt; db.foo.find({attrs: {$elemMatch: &lt;/p&gt;
{n: &quot;low&quot;, v: 100}
&lt;p&gt;}})&lt;br/&gt;
{ &quot;_id&quot; : ObjectId(&quot;4d66b227d6eb5559fa645ce1&quot;), &quot;attrs&quot; : [ &lt;/p&gt;
{ &quot;n&quot; : &quot;low&quot;, &quot;v&quot; : 100 }
&lt;p&gt;, &lt;/p&gt;
{ &quot;n&quot; : &quot;high&quot;, &quot;v&quot; : 100 }
&lt;p&gt; ] }&lt;/p&gt;

&lt;p&gt;Is this the expected behavior?&lt;/p&gt;




</description>
                <environment></environment>
        <key id="14875">SERVER-2620</key>
            <summary>Multi-key indexes on arrays of object with more than one key cause queries to behave like $elemMatch by default.</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="3">Duplicate</resolution>
                                        <assignee username="aaron">Aaron Staple</assignee>
                                    <reporter username="kbanker">Kyle Banker</reporter>
                        <labels>
                    </labels>
                <created>Thu, 24 Feb 2011 19:38:40 +0000</created>
                <updated>Tue, 29 May 2012 14:53:27 +0000</updated>
                            <resolved>Tue, 7 Jun 2011 16:18:11 +0000</resolved>
                                                                    <component>Index Maintenance</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="36560" author="aaron" created="Tue, 7 Jun 2011 16:18:11 +0000"  >&lt;p&gt;This was fixed as part of the &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-958&quot; title=&quot;Range queries on arrays behave differently with indexes&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-958&quot;&gt;&lt;del&gt;SERVER-958&lt;/del&gt;&lt;/a&gt; work.&lt;/p&gt;</comment>
                            <comment id="25233" author="psionides" created="Fri, 4 Mar 2011 09:57:14 +0000"  >&lt;p&gt;I also found this issue... I have a &quot;profiles&quot; collection with &quot;services&quot; field and the services have &quot;type&quot; and &quot;username&quot; fields. I was trying to show another developer that he needs to use $elemMatch to look for services with type and username, otherwise he may find a profile whose one service matches type and another service matches username. Turns out, it didn&apos;t work... and I found that this is because of an index we have on profiles on &lt;span class=&quot;error&quot;&gt;&amp;#91;services.type, services.username&amp;#93;&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;On the wiki there is an example that explains why $elemMatch should be necessary in this case: &lt;a href=&quot;http://www.mongodb.org/display/DOCS/Dot+Notation+(Reaching+into+Objects&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.mongodb.org/display/DOCS/Dot+Notation+(Reaching+into+Objects&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Now, if I create the two records from the example:&lt;/p&gt;

&lt;p&gt;&amp;gt; db.foo.save({ foo: [ &lt;/p&gt;
{ shape: &quot;square&quot;, color: &quot;purple&quot;, thick: false }
&lt;p&gt;, &lt;/p&gt;
{ shape: &quot;circle&quot;, color: &quot;red&quot;, thick: true }
&lt;p&gt; ] }) &lt;br/&gt;
&amp;gt; db.foo.save({ foo: [ &lt;/p&gt;
{ shape: &quot;square&quot;, color: &quot;red&quot;, thick: true }
&lt;p&gt;, &lt;/p&gt;
{ shape: &quot;circle&quot;, color: &quot;purple&quot;, thick: false }
&lt;p&gt; ] }) &lt;/p&gt;

&lt;p&gt;And then search:&lt;/p&gt;

&lt;p&gt;&amp;gt; db.foo.find(&lt;/p&gt;
{ &quot;foo.shape&quot;: &quot;square&quot;, &quot;foo.color&quot;: &quot;purple&quot; }
&lt;p&gt;) &lt;/p&gt;

&lt;p&gt;I get two records. But if I add an index and then search again: &lt;/p&gt;

&lt;p&gt;&amp;gt; db.foo.ensureIndex(&lt;/p&gt;
{ &quot;foo.shape&quot;: 1, &quot;foo.color&quot;: 1 }
&lt;p&gt;) &lt;br/&gt;
&amp;gt; db.foo.find(&lt;/p&gt;
{ &quot;foo.shape&quot;: &quot;square&quot;, &quot;foo.color&quot;: &quot;purple&quot; }
&lt;p&gt;) &lt;/p&gt;

&lt;p&gt;Then I get only one record (the first one). And if for some reason the index isn&apos;t used, even though it exists (perhaps because another index is used): &lt;/p&gt;

&lt;p&gt;&amp;gt; db.foo.find(&lt;/p&gt;
{ &quot;foo.shape&quot;: &quot;square&quot;, &quot;foo.color&quot;: &quot;purple&quot; }
&lt;p&gt;).hint(&lt;/p&gt;
{ $natural: 1 }
&lt;p&gt;) &lt;/p&gt;

&lt;p&gt;Then you still get 2 records... So the result may be that the algorithm for matching is different depending on whether an index is used or not, and you can&apos;t always know which index will be used, so your system may behave a bit non-deterministically... I&apos;d say such kind of behavior is a bug.&lt;/p&gt;</comment>
                            <comment id="24671" author="eliot" created="Fri, 25 Feb 2011 15:33:57 +0000"  >&lt;p&gt;Actually creating that index should fail as your&apos;e really doing an N^2 index.&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>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Fri, 25 Feb 2011 15:33:57 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        12 years, 37 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>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, 37 weeks, 1 day 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>aaron</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>psionides</customfieldvalue>
            <customfieldvalue>kbanker</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrij7b:</customfieldvalue>

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

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

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