<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:57:53 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-1735] Inconsistent behaviour for $exists: false and $type: 10 in query</title>
                <link>https://jira.mongodb.org/browse/SERVER-1735</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;key: {$exists: false} / key: {$type: 10} / key: null quering gives inconsistent and unpredictable behaviour, so to workraound needed to implement querying of this kind of parameters&lt;/p&gt;


&lt;p&gt;shell script example:&lt;br/&gt;
db.testcollection.ensureIndex(&lt;/p&gt;
{date: -1, country_code: 1, user_id: 1}
&lt;p&gt;, &lt;/p&gt;
{unique: 1, background: 1}
&lt;p&gt;); &lt;br/&gt;
db.testcollection.insert(&lt;/p&gt;
{ date: new Date(&quot;08/27/2010&quot;), tot_visit: 100}
&lt;p&gt;); &lt;br/&gt;
db.testcollection.insert(&lt;/p&gt;
{ date: new Date(&quot;08/27/2010&quot;), country_code: &quot;IT&quot;, tot_visit: 77}
&lt;p&gt;); &lt;br/&gt;
db.testcollection.insert(&lt;/p&gt;
{ date: new Date(&quot;08/27/2010&quot;), country_code: &quot;ES&quot;, tot_visit: 23}
&lt;p&gt;); &lt;br/&gt;
db.testcollection.insert(&lt;/p&gt;
{ date: new Date(&quot;08/27/2010&quot;), country_code: &quot;ES&quot;, user_id: &quot;and...@spacca.org&quot;, tot_visit: 11}
&lt;p&gt;); &lt;br/&gt;
db.testcollection.insert(&lt;/p&gt;
{ date: new Date(&quot;08/27/2010&quot;), country_code: &quot;ES&quot;, user_id: &quot;andrea.spa...@gmail.com&quot;, tot_visit: 5}
&lt;p&gt;); &lt;br/&gt;
db.testcollection.insert(&lt;/p&gt;
{ date: new Date(&quot;08/27/2010&quot;), country_code: &quot;ES&quot;, user_id: &quot;andrea.spa...@progloedizioni.com&quot;, tot_visit: 7}
&lt;p&gt;); &lt;/p&gt;


&lt;p&gt;db.testcollection.find(&lt;/p&gt;
{date: new Date(&quot;08/27/2010&quot;)}
&lt;p&gt;).count(); // 6 &lt;span class=&quot;error&quot;&gt;&amp;#91;OK&amp;#93;&lt;/span&gt; &lt;br/&gt;
db.testcollection.find({date: new Date(&quot;08/27/2010&quot;), country_code: {$exists: true}}).count(); // 5 &lt;span class=&quot;error&quot;&gt;&amp;#91;OK&amp;#93;&lt;/span&gt; &lt;br/&gt;
db.testcollection.find({date: new Date(&quot;08/27/2010&quot;), country_code: {$exists: false}}).count(); // 1 &lt;span class=&quot;error&quot;&gt;&amp;#91;OK&amp;#93;&lt;/span&gt; &lt;br/&gt;
db.testcollection.find({date: new Date(&quot;08/27/2010&quot;), country_code: {$type: 10}}).count(); // 1 &lt;span class=&quot;error&quot;&gt;&amp;#91;OK&amp;#93;&lt;/span&gt; &lt;br/&gt;
db.testcollection.find(&lt;/p&gt;
{date: new Date(&quot;08/27/2010&quot;), country_code: null}
&lt;p&gt;).count(); // 1 &lt;span class=&quot;error&quot;&gt;&amp;#91;OK&amp;#93;&lt;/span&gt; &lt;br/&gt;
db.testcollection.find({date: new Date(&quot;08/27/2010&quot;), country_code: {$exists: true}, user_id: {$exists: true}}).count(); // 3 &lt;span class=&quot;error&quot;&gt;&amp;#91;OK&amp;#93;&lt;/span&gt; &lt;br/&gt;
db.testcollection.find({date: new Date(&quot;08/27/2010&quot;), country_code: {$exists: true}, user_id: {$exists: false}}).count(); // 2 &lt;span class=&quot;error&quot;&gt;&amp;#91;OK&amp;#93;&lt;/span&gt; &lt;br/&gt;
db.testcollection.find({date: new Date(&quot;08/27/2010&quot;), country_code: {$exists: true}, user_id: {$type: 10}}).count(); // 0 &lt;span class=&quot;error&quot;&gt;&amp;#91;??&amp;#93;&lt;/span&gt;&lt;br/&gt;
db.testcollection.find({date: new Date(&quot;08/27/2010&quot;), country_code: {$exists: true}, user_id: null}).count(); // 2 &lt;span class=&quot;error&quot;&gt;&amp;#91;OK&amp;#93;&lt;/span&gt;&lt;/p&gt;



&lt;p&gt;changing the order of key querying or indexing produces slightly different results, always bogus&lt;/p&gt;</description>
                <environment>Tested as bogus in macosx 10.6.4 server 64bit and Ubuntu 9.10 64bit</environment>
        <key id="13012">SERVER-1735</key>
            <summary>Inconsistent behaviour for $exists: false and $type: 10 in query</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="aaron">Aaron Staple</assignee>
                                    <reporter username="aspacca">Andrea Spacca</reporter>
                        <labels>
                    </labels>
                <created>Sat, 4 Sep 2010 17:56:25 +0000</created>
                <updated>Tue, 12 Jul 2016 00:17:18 +0000</updated>
                            <resolved>Fri, 3 Jun 2011 15:12:23 +0000</resolved>
                                    <version>1.6.1</version>
                    <version>1.6.2</version>
                    <version>1.7.0</version>
                                    <fixVersion>1.9.1</fixVersion>
                                    <component>Querying</component>
                                        <votes>1</votes>
                                    <watches>5</watches>
                                                                                                                <comments>
                            <comment id="35964" author="auto" created="Fri, 3 Jun 2011 15:31:28 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;astaple&apos;, u&apos;name&apos;: u&apos;Aaron&apos;, u&apos;email&apos;: u&apos;aaron@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1735&quot; title=&quot;Inconsistent behaviour for $exists: false and $type: 10 in query&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1735&quot;&gt;&lt;del&gt;SERVER-1735&lt;/del&gt;&lt;/a&gt; add a real field value test case&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/ba9daf00db064ef9a284f5b72bb3e43a0ca141bb&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/ba9daf00db064ef9a284f5b72bb3e43a0ca141bb&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="35949" author="aaron" created="Fri, 3 Jun 2011 15:02:27 +0000"  >&lt;p&gt;Our behavior now is&lt;/p&gt;

{a:null}
&lt;p&gt; - match if a is null or missing&lt;br/&gt;
{a:{$exists:true}} - match if a is present&lt;br/&gt;
{a:{$exists:false}} - match if a is missing&lt;br/&gt;
{a:{$type:10}} - match if a is null, but not if a is missing or present and nonnull&lt;/p&gt;</comment>
                            <comment id="35823" author="auto" created="Thu, 2 Jun 2011 21:08:49 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;astaple&apos;, u&apos;name&apos;: u&apos;Aaron&apos;, u&apos;email&apos;: u&apos;aaron@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1735&quot; title=&quot;Inconsistent behaviour for $exists: false and $type: 10 in query&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1735&quot;&gt;&lt;del&gt;SERVER-1735&lt;/del&gt;&lt;/a&gt; type:10 query matches null value but not missing value, hence an index check is insufficient to do a match&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/37d36b7cf1f3a0b8b2a7639b91976673377fd47c&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/37d36b7cf1f3a0b8b2a7639b91976673377fd47c&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="27870" author="aaron" created="Tue, 5 Apr 2011 20:40:06 +0000"  >&lt;p&gt;The exists:false failure is &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1587&quot; title=&quot;$exists:false not working correctly&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1587&quot;&gt;&lt;del&gt;SERVER-1587&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="22775" author="guanqun" created="Fri, 28 Jan 2011 08:12:41 +0000"  >&lt;p&gt;come up with a more compact fix, as this type info is already maintained in bm.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo/pull/14/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/pull/14/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;any comments?&lt;/p&gt;</comment>
                            <comment id="22322" author="guanqun" created="Thu, 13 Jan 2011 13:04:48 +0000"  >&lt;p&gt;I did some hacking on this problem and found&lt;/p&gt;

&lt;p&gt;db/matcher.cpp bool Matcher::matches(const BSONObj&amp;amp; jsobj , MatchDetails * details ) &lt;/p&gt;

&lt;p&gt; 764             if ( cmp == 0 ) {&lt;br/&gt;
 765                 /* missing is ok iff we were looking for null */&lt;br/&gt;
 766                 if ( m.type() == jstNULL || m.type() == Undefined || ( bm.compareOp == BSONObj::opIN &amp;amp;&amp;amp; bm.myset-&amp;gt;count( staticNull.firstElement() ) &amp;gt; 0 ) ) {&lt;br/&gt;
 767                     if ( ( bm.compareOp == BSONObj::NE ) ^ bm.isNot ) &lt;/p&gt;
{
 768                         return false;
 769                     }

&lt;p&gt;at line 766 shown above, for ElementMatcher &lt;/p&gt;
{ $type : 10 }
&lt;p&gt; to match user_id, at this point, m.type() is NumberDouble (value is 10.0), and the compareOp is 15 (opTYPE). we should take this case into consideration because we&apos;re actually looking for null.&lt;/p&gt;

&lt;p&gt;the corresponding fix is here. and i&apos;ve added a jstest for this bug.&lt;br/&gt;
    &lt;a href=&quot;https://github.com/guanqun/mongo/commit/07201282d7b91323280ae9d0465ba8872208829c&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/guanqun/mongo/commit/07201282d7b91323280ae9d0465ba8872208829c&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;please review,&lt;br/&gt;
this patch changes the core part of the server, hope i&apos;m not missing something and causes regression by accident.&lt;/p&gt;</comment>
                            <comment id="20000" author="dougtmayer" created="Wed, 3 Nov 2010 15:10:12 +0000"  >&lt;p&gt;The following line is noted as OK above:&lt;/p&gt;

&lt;p&gt;db.testcollection.find({date: new Date(&quot;08/27/2010&quot;), country_code: {$exists: true}, user_id: {$exists: false}}).count(); // 2 &lt;span class=&quot;error&quot;&gt;&amp;#91;OK&amp;#93;&lt;/span&gt; &lt;/p&gt;

&lt;p&gt;On Mac OSX 64-bit, v1.6.3, this line actually returns ZERO records. There seems to be a lot of inconsistent behavior around $exists in 1.6.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                        <issuelink>
            <issuekey id="12703">SERVER-1587</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>7.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Wed, 3 Nov 2010 15:10:12 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        12 years, 37 weeks, 5 days 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-1587'>SERVER-1587</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>
                            12 years, 37 weeks, 5 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>aaron</customfieldvalue>
            <customfieldvalue>aspacca</customfieldvalue>
            <customfieldvalue>auto</customfieldvalue>
            <customfieldvalue>dougtmayer</customfieldvalue>
            <customfieldvalue>guanqun</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpfvz:</customfieldvalue>

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

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

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