<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:23:36 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-10608] {$exists: false} will not use index</title>
                <link>https://jira.mongodb.org/browse/SERVER-10608</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;If you&apos;re doing a query with exists, it will not use the index. &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-393&quot; title=&quot;$exists queries should use index&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-393&quot;&gt;&lt;del&gt;SERVER-393&lt;/del&gt;&lt;/a&gt; was supposed to fix this afaik, but it is still forcing queries to not use the index, even if there is a more suitable one (including the exists field). If I use $hint to force it to use an index, then it just ignores the $exists.&lt;/p&gt;

&lt;p&gt;Additionally, if I use $hint, then the documents returned do NOT contain that field even if they should&apos;ve. It&apos;s like I added a projection with that field being excluded. This might be a different bug though.&lt;/p&gt;

&lt;p&gt;See steps to reproduce for a test case.&lt;/p&gt;</description>
                <environment></environment>
        <key id="87109">SERVER-10608</key>
            <summary>{$exists: false} will not use index</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="benety.goh@mongodb.com">Benety Goh</assignee>
                                    <reporter username="fastest963">James Hartig</reporter>
                        <labels>
                            <label>indexes</label>
                            <label>query_triage</label>
                    </labels>
                <created>Fri, 23 Aug 2013 01:47:14 +0000</created>
                <updated>Wed, 2 Jan 2019 22:28:18 +0000</updated>
                            <resolved>Wed, 29 Jan 2014 16:02:55 +0000</resolved>
                                    <version>2.2.3</version>
                                    <fixVersion>2.5.5</fixVersion>
                                    <component>Querying</component>
                                        <votes>1</votes>
                                    <watches>7</watches>
                                                                                                                <comments>
                            <comment id="2103804" author="ramon.fernandez" created="Wed, 2 Jan 2019 22:28:18 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=ohadr&quot; class=&quot;user-hover&quot; rel=&quot;ohadr&quot;&gt;ohadr&lt;/a&gt;, will you please open a new SERVER ticket and provide details of the issue you&apos;re running into? We&apos;ll need to see the output of your queries run with &lt;tt&gt;explain()&lt;/tt&gt;. Note though that MongoDB 3.2 is no longer supported, so my recommendation is to upgrade to a supported version (preferably 4.0) and report back if you think something is not working correctly.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Ram&#243;n.&lt;/p&gt;</comment>
                            <comment id="2100859" author="ohadr" created="Thu, 27 Dec 2018 13:42:58 +0000"  >&lt;p&gt;is this still relevant to mongodb v.3 and above? i have mongo 3.2, and i invoke a query with &quot;$exists&quot; on a key which is indexed. it takes a lot of time, and when i make the call with explain(true), i see that it traverses over all the docs in the collection.&lt;/p&gt;

&lt;p&gt;is it a bug? if so, should this bug be reopened, or should i open a new bug for the 3.2 version?&lt;/p&gt;</comment>
                            <comment id="516080" author="benety.goh" created="Fri, 14 Mar 2014 13:33:13 +0000"  >&lt;p&gt;This fix was made to the new query framework introduced in 2.6. There&apos;s been a lot of code movement since 2.2. I&apos;m not sure if a cherry-pick will help.&lt;/p&gt;</comment>
                            <comment id="515908" author="fastest963" created="Fri, 14 Mar 2014 04:17:31 +0000"  >&lt;p&gt;Any updates on a backport to 2.2 or any help with a manual cherry-pick?&lt;/p&gt;</comment>
                            <comment id="490088" author="samantha.ritter@10gen.com" created="Wed, 29 Jan 2014 16:02:55 +0000"  >&lt;p&gt;Discussed this with Benety, and the case I was trying is a slightly different case than this ticket deals with.&lt;/p&gt;</comment>
                            <comment id="465916" author="fastest963" created="Thu, 5 Dec 2013 00:22:04 +0000"  >&lt;p&gt;If you cannot backport the fix, which commits are necessary to cherry-pick to 2.2 so we can manually apply the fix? It seems like the bea51dd commit just added a test and the real fix was in 0498f81, correct?&lt;/p&gt;</comment>
                            <comment id="465769" author="xgen-internal-githook" created="Wed, 4 Dec 2013 20:59:03 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;benety&apos;, u&apos;name&apos;: u&apos;Benety Goh&apos;, u&apos;email&apos;: u&apos;benety@mongodb.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-10608&quot; title=&quot;{$exists: false} will not use index&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-10608&quot;&gt;&lt;del&gt;SERVER-10608&lt;/del&gt;&lt;/a&gt; added test cases for exists operator&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/bea51dd281f49b3f0bf0fb6fa627d01205b72de4&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/bea51dd281f49b3f0bf0fb6fa627d01205b72de4&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="465661" author="fastest963" created="Wed, 4 Dec 2013 19:15:29 +0000"  >&lt;p&gt;Can the negation fix be backported then in addition? The problem is that, at Grooveshark, we cannot upgrade from 2.0 to 2.4+ without first going through 2.2 according to the migration docs, and we cannot upgrade to 2.2 without the server crashing since this bug causes some of our queries to not use any indexes. Without this fix, or a clean migration path from 2.0 to 2.4+, we are stuck on 2.0 unless we want to incur downtime.&lt;/p&gt;</comment>
                            <comment id="465645" author="benety.goh" created="Wed, 4 Dec 2013 19:04:23 +0000"  >&lt;p&gt;case 2 in test script depends on negation fix&lt;/p&gt;</comment>
                            <comment id="451390" author="fastest963" created="Tue, 5 Nov 2013 05:10:09 +0000"  >&lt;p&gt;The fix is slated for 2.5.x release. Can it get backported to 2.2.x?&lt;/p&gt;</comment>
                            <comment id="450115" author="benety.goh" created="Fri, 1 Nov 2013 15:00:45 +0000"  >&lt;p&gt;includes both $exists: true and $exists: false cases on non-indexed field&lt;/p&gt;</comment>
                            <comment id="409652" author="fastest963" created="Fri, 23 Aug 2013 02:41:36 +0000"  >&lt;p&gt;Managed to test this on 2.0.8 and it uses the index fine, so this looks like a regression in 2.2.x.&lt;/p&gt;</comment>
                            <comment id="409645" author="fastest963" created="Fri, 23 Aug 2013 02:27:08 +0000"  >&lt;p&gt;For an immediate fix for {$exists: false} use null instead.&lt;/p&gt;

&lt;p&gt;db.test.find(&lt;/p&gt;
{c: 5, b: null}
&lt;p&gt;).explain()&lt;br/&gt;
{&lt;br/&gt;
    &quot;cursor&quot; : &quot;BtreeCursor c_1&quot;,&lt;br/&gt;
    &quot;isMultiKey&quot; : false,&lt;br/&gt;
    &quot;n&quot; : 2,&lt;br/&gt;
    &quot;nscannedObjects&quot; : 3,&lt;br/&gt;
    &quot;nscanned&quot; : 3,&lt;br/&gt;
    &quot;nscannedObjectsAllPlans&quot; : 6,&lt;br/&gt;
    &quot;nscannedAllPlans&quot; : 6,&lt;br/&gt;
    &quot;scanAndOrder&quot; : false,&lt;br/&gt;
    &quot;indexOnly&quot; : false,&lt;br/&gt;
    &quot;nYields&quot; : 0,&lt;br/&gt;
    &quot;nChunkSkips&quot; : 0,&lt;br/&gt;
    &quot;millis&quot; : 0,&lt;br/&gt;
    &quot;indexBounds&quot; : &lt;/p&gt;
{
            &quot;c&quot; : [
                    [
                            5,
                            5
                    ]
            ]
    }
&lt;p&gt;,&lt;br/&gt;
    &quot;server&quot; : &quot;test:27017&quot;&lt;br/&gt;
}&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                        <issuelink>
            <issuekey id="96211">SERVER-11446</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="80117">SERVER-10005</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="36867" name="existsindex.js" size="634" author="samantha.ritter@mongodb.com" created="Tue, 28 Jan 2014 21:33:03 +0000"/>
                            <attachment id="33314" name="server10608.js" size="889" author="benety.goh@mongodb.com" created="Fri, 1 Nov 2013 15:27:21 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>13.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Fri, 1 Nov 2013 15:00:45 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        5 years, 6 weeks ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[<s><a href='https://jira.mongodb.org/browse/SERVER-11446'>SERVER-11446</a></s>]]></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>
                            5 years, 6 weeks 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>benety.goh@mongodb.com</customfieldvalue>
            <customfieldvalue>xgen-internal-githook</customfieldvalue>
            <customfieldvalue>fastest963</customfieldvalue>
            <customfieldvalue>ohadr</customfieldvalue>
            <customfieldvalue>ramon.fernandez@mongodb.com</customfieldvalue>
            <customfieldvalue>samantha.ritter@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrmikv:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>79862</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_10750" key="com.atlassian.jira.plugin.system.customfieldtypes:textarea">
                        <customfieldname>Steps To Reproduce</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>&lt;p&gt;Here&apos;s an example collection&apos;s index (besides _id):&lt;br/&gt;
{&lt;br/&gt;
    &quot;v&quot; : 1,&lt;br/&gt;
    &quot;key&quot; : &lt;/p&gt;
{
            &quot;c&quot; : 1
    }
&lt;p&gt;,&lt;br/&gt;
    &quot;ns&quot; : &quot;test.test&quot;,&lt;br/&gt;
    &quot;name&quot; : &quot;c_1&quot;,&lt;br/&gt;
    &quot;background&quot; : true,&lt;br/&gt;
    &quot;sparse&quot; : true&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;There are 6 items:&lt;br/&gt;
db.test.insert(&lt;/p&gt;
{c: 5, b: 1}
&lt;p&gt;);&lt;br/&gt;
db.test.insert(&lt;/p&gt;
{c: 5}
&lt;p&gt;);&lt;br/&gt;
db.test.insert(&lt;/p&gt;
{c: 4}
&lt;p&gt;);&lt;br/&gt;
db.test.insert(&lt;/p&gt;
{c: 3}
&lt;p&gt;);&lt;br/&gt;
db.test.insert(&lt;/p&gt;
{c: 5}
&lt;p&gt;);&lt;br/&gt;
db.test.insert(&lt;/p&gt;
{c: 1}
&lt;p&gt;);&lt;/p&gt;

&lt;p&gt;db.test.find({c: 5, b: {$exists: false}}).explain()&lt;br/&gt;
{&lt;br/&gt;
        &quot;cursor&quot; : &quot;BasicCursor&quot;,&lt;br/&gt;
        &quot;isMultiKey&quot; : false,&lt;br/&gt;
        &quot;n&quot; : 2,&lt;br/&gt;
        &quot;nscannedObjects&quot; : 6,&lt;br/&gt;
        &quot;nscanned&quot; : 6,&lt;br/&gt;
        &quot;nscannedObjectsAllPlans&quot; : 6,&lt;br/&gt;
        &quot;nscannedAllPlans&quot; : 6,&lt;br/&gt;
        &quot;scanAndOrder&quot; : false,&lt;br/&gt;
        &quot;indexOnly&quot; : false,&lt;br/&gt;
        &quot;nYields&quot; : 0,&lt;br/&gt;
        &quot;nChunkSkips&quot; : 0,&lt;br/&gt;
        &quot;millis&quot; : 0,&lt;br/&gt;
        &quot;indexBounds&quot; : {&lt;/p&gt;

&lt;p&gt;        },&lt;br/&gt;
        &quot;server&quot; : &quot;test:27017&quot;&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Even if I add an index on &lt;/p&gt;
{c: 1, b: 1}
&lt;p&gt; it won&apos;t use that index either.&lt;/p&gt;

&lt;p&gt;With hint (where did the &quot;b&quot;: 1 go on the first item?):&lt;br/&gt;
db.test.find({c: 5, b: {$exists: false}}).hint(&lt;/p&gt;
{c: 1}
&lt;p&gt;)&lt;/p&gt;
{ &quot;_id&quot; : ObjectId(&quot;5216bcf5f2aa2ebe3c6ed298&quot;), &quot;c&quot; : 5 }
{ &quot;_id&quot; : ObjectId(&quot;5216bcf5f2aa2ebe3c6ed295&quot;), &quot;c&quot; : 5 }</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_10166" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Tests Written</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10154"><![CDATA[Complete]]></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_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|hri9nb:</customfieldvalue>

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