<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:24:32 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-10971] Mongodb compound 2dsphere index dosen&apos;t work as expected</title>
                <link>https://jira.mongodb.org/browse/SERVER-10971</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I have a collection called search2 with about 20000 documents like this:&lt;/p&gt;

&lt;p&gt;    {&lt;br/&gt;
        &quot;loc&quot;: &lt;/p&gt;
{
        &quot;type&quot;: &quot;Polygon&quot;,
        &quot;coordinates&quot;: [
            [
            [
                43.78526674007639,
                11.14739998758569
            ],
            [
                43.78526674007639,
                11.183372851822439
            ],
            [
                43.79443488391605,
                11.183372851822439
            ],
            [
                43.79443488391605,
                11.264311796355125
            ],
            [
                43.812771171595415,
                11.264311796355125
            ],
            [
                43.83110745927479,
                11.264311796355125
            ],
            [
                43.83110745927479,
                11.273305012414314
            ],
            [
                43.849443746954144,
                11.273305012414314
            ],
            [
                43.858611890793824,
                11.273305012414314
            ],
            [
                43.858611890793824,
                11.264311796355125
            ],
            [
                43.8769481784732,
                11.264311796355125
            ],
            [
                43.8769481784732,
                11.246325364236752
            ],
            [
                43.88611632231286,
                11.246325364236752
            ],
            [
                43.88611632231286,
                11.237332148177565
            ],
            [
                43.895284466152546,
                11.237332148177565
            ],
            [
                43.895284466152546,
                11.228338932118376
            ],
            [
                43.904452609992234,
                11.228338932118376
            ],
            [
                43.904452609992234,
                11.165386419704065
            ],
            [
                43.895284466152546,
                11.165386419704065
            ],
            [
                43.895284466152546,
                11.156393203644878
            ],
            [
                43.88611632231286,
                11.156393203644878
            ],
            [
                43.8769481784732,
                11.156393203644878
            ],
            [
                43.858611890793824,
                11.156393203644878
            ],
            [
                43.849443746954144,
                11.156393203644878
            ],
            [
                43.849443746954144,
                11.165386419704065
            ],
            [
                43.83110745927479,
                11.165386419704065
            ],
            [
                43.83110745927479,
                11.156393203644878
            ],
            [
                43.812771171595415,
                11.156393203644878
            ],
            [
                43.812771171595415,
                11.14739998758569
            ],
            [
                43.79443488391605,
                11.14739998758569
            ],
            [
                43.78526674007639,
                11.14739998758569
            ]
            ]
        ]
        }
&lt;p&gt;,&lt;br/&gt;
        &quot;docId&quot;: 1,&lt;br/&gt;
        &quot;docVote&quot;: 0,&lt;br/&gt;
        &quot;title&quot;: &quot;title-1&quot;,&lt;br/&gt;
        &quot;_id&quot;: &lt;/p&gt;
{
        &quot;$oid&quot;: &quot;5248725d2dd5622510000001&quot;
        }
&lt;p&gt;    }&lt;br/&gt;
I define an index with this command:&lt;/p&gt;

&lt;p&gt;    db.search2.ensureIndex(&lt;/p&gt;
{&quot;docVote&quot;: 1,&quot;loc&quot;:&quot;2dsphere&quot;}
&lt;p&gt;);&lt;br/&gt;
On the collection there are only this index and the default index on &quot;_id&quot; field.&lt;/p&gt;

&lt;p&gt;When i execute the following query i expect &quot;nscannedObjects&quot; to be = 10 :&lt;/p&gt;

&lt;p&gt;    db.search2.find({&lt;br/&gt;
        loc: {&lt;br/&gt;
        $geoIntersects: {&lt;br/&gt;
            $geometry: &lt;/p&gt;
{
            type: &quot;Polygon&quot;,
            coordinates: [
                [
                    [43.7269795, 11.1540365],
                    [43.8329368, 11.1540365],
                    [43.8329368, 11.3310908],
                    [43.7269795, 11.3310908],
                    [43.7269795, 11.1540365]
                ]
            ]
            }
&lt;p&gt;        }&lt;br/&gt;
        }&lt;br/&gt;
    }, &lt;/p&gt;
{
        &quot;docVote&quot;: 1,
        _id: 0
    }
&lt;p&gt;).sort(&lt;/p&gt;
{
        &quot;docVote&quot;: 1
    }
&lt;p&gt;).limit(10).hint(&lt;/p&gt;
{
        &quot;docVote&quot;: 1,
        &quot;loc&quot;: &quot;2dsphere&quot;
    }
&lt;p&gt;).explain()&lt;br/&gt;
But this is the result:&lt;/p&gt;

&lt;p&gt;    {&lt;br/&gt;
    &quot;cursor&quot; : &quot;S2Cursor&quot;,&lt;br/&gt;
    &quot;isMultiKey&quot; : true,&lt;br/&gt;
    &quot;n&quot; : 10,&lt;br/&gt;
    &quot;nscannedObjects&quot; : 44283,&lt;br/&gt;
    &quot;nscanned&quot; : 648117,&lt;br/&gt;
    &quot;nscannedObjectsAllPlans&quot; : 44283,&lt;br/&gt;
    &quot;nscannedAllPlans&quot; : 648117,&lt;br/&gt;
    &quot;scanAndOrder&quot; : true,&lt;br/&gt;
    &quot;indexOnly&quot; : false,&lt;br/&gt;
    &quot;nYields&quot; : 13,&lt;br/&gt;
    &quot;nChunkSkips&quot; : 0,&lt;br/&gt;
    &quot;millis&quot; : 12632,&lt;br/&gt;
    &quot;indexBounds&quot; : {&lt;/p&gt;

&lt;p&gt;    },&lt;br/&gt;
    &quot;nscanned&quot; : 648117,&lt;br/&gt;
    &quot;matchTested&quot; : NumberLong(46642),&lt;br/&gt;
    &quot;geoTested&quot; : NumberLong(46642),&lt;br/&gt;
    &quot;cellsInCover&quot; : NumberLong(8),&lt;br/&gt;
    &quot;server&quot; : &quot;*********&quot;&lt;br/&gt;
    }&lt;br/&gt;
If i remove sort from the query i obtain this:&lt;/p&gt;

&lt;p&gt;    {&lt;br/&gt;
        &quot;cursor&quot; : &quot;S2Cursor&quot;,&lt;br/&gt;
        &quot;isMultiKey&quot; : true,&lt;br/&gt;
        &quot;n&quot; : 10,&lt;br/&gt;
        &quot;nscannedObjects&quot; : 10,&lt;br/&gt;
        &quot;nscanned&quot; : 25,&lt;br/&gt;
        &quot;nscannedObjectsAllPlans&quot; : 10,&lt;br/&gt;
        &quot;nscannedAllPlans&quot; : 25,&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; : 3,&lt;br/&gt;
        &quot;indexBounds&quot; : {&lt;/p&gt;

&lt;p&gt;        },&lt;br/&gt;
        &quot;nscanned&quot; : 25,&lt;br/&gt;
        &quot;matchTested&quot; : NumberLong(10),&lt;br/&gt;
        &quot;geoTested&quot; : NumberLong(10),&lt;br/&gt;
        &quot;cellsInCover&quot; : NumberLong(8),&lt;br/&gt;
        &quot;server&quot; : &quot;******&quot;&lt;br/&gt;
    }&lt;br/&gt;
So, why index is not used to sort results? From this documentation: &lt;a href=&quot;http://docs.mongodb.org/manual/applications/geospatial-indexes/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/manual/applications/geospatial-indexes/&lt;/a&gt; &lt;a href=&quot;http://docs.mongodb.org/manual/tutorial/sort-results-with-indexes/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/manual/tutorial/sort-results-with-indexes/&lt;/a&gt; I understand that MongoDb support &quot;A compound index with scalar index fields (i.e. ascending or descending) as a prefix or suffix of the 2dsphere index field&quot; and that &quot;If the sort document is a subset of a compound index and starts from the beginning of the index, MongoDB can use the index to both retrieve and sort the query results.&quot;&lt;/p&gt;

&lt;p&gt;What am I missing?&lt;/p&gt;

&lt;p&gt;Thanks in advance&lt;/p&gt;</description>
                <environment></environment>
        <key id="92156">SERVER-10971</key>
            <summary>Mongodb compound 2dsphere index dosen&apos;t work as expected</summary>
                <type id="6" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14720&amp;avatarType=issuetype">Question</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="-1">Unassigned</assignee>
                                    <reporter username="MarcoBiagi">Marco Biagi</reporter>
                        <labels>
                            <label>2dsphere</label>
                            <label>geo</label>
                            <label>geoIntersects</label>
                            <label>index</label>
                    </labels>
                <created>Mon, 30 Sep 2013 20:47:57 +0000</created>
                <updated>Wed, 10 Dec 2014 23:04:33 +0000</updated>
                            <resolved>Thu, 3 Oct 2013 05:30:37 +0000</resolved>
                                    <version>2.4.6</version>
                                                    <component>Geo</component>
                    <component>Index Maintenance</component>
                                        <votes>1</votes>
                                    <watches>5</watches>
                                                                                                                <comments>
                            <comment id="435019" author="dan@10gen.com" created="Thu, 3 Oct 2013 05:30:37 +0000"  >&lt;p&gt;duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-10801&quot; title=&quot;Allow compound geo indexes to be able to provide sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-10801&quot;&gt;SERVER-10801&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="434750" author="marcobiagi" created="Wed, 2 Oct 2013 18:50:32 +0000"  >&lt;p&gt;I think that is a bug, not a question. It can be related to &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-10801&quot; title=&quot;Allow compound geo indexes to be able to provide sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-10801&quot;&gt;SERVER-10801&lt;/a&gt;. In issue 10801 sort field is a timestamp. In my case is a float/integer.&lt;/p&gt;</comment>
                            <comment id="434521" author="marcobiagi" created="Wed, 2 Oct 2013 13:50:25 +0000"  >&lt;p&gt;What did you mean with &quot;  debugging with submitter&quot;? I must do something?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="90453">SERVER-10801</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>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Thu, 3 Oct 2013 05:30:37 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        10 years, 19 weeks, 6 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>
                            10 years, 19 weeks, 6 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_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>dan@mongodb.com</customfieldvalue>
            <customfieldvalue>MarcoBiagi</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrme9b:</customfieldvalue>

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

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

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