<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:32:08 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-13569] sort() after geoNear/geoWithin find/aggregate doesn&apos;t use the index</title>
                <link>https://jira.mongodb.org/browse/SERVER-13569</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Sorting a result by a single field on a find() or aggregate() result that uses geoNear or geoWithin and limiting the result (e.g. to 1,000 documents) yields a very slow response time. Running explain shows scanAndOrder=true and a very high number of scanned documents.&lt;/p&gt;

&lt;p&gt;If you remove the geoNear/geoWithin and get the whole collection, the sort is very fast, and explain shows scanAndOrder=false and a number of low number of scanned documents, which is equal to the limit specified.&lt;/p&gt;</description>
                <environment></environment>
        <key id="130818">SERVER-13569</key>
            <summary>sort() after geoNear/geoWithin find/aggregate doesn&apos;t use the 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="thomas.rueckstiess@mongodb.com">Thomas Rueckstiess</assignee>
                                    <reporter username="aplimovil">Abraham Lopez</reporter>
                        <labels>
                            <label>geoNear</label>
                            <label>geoWithin</label>
                            <label>sort</label>
                            <label>sorting</label>
                    </labels>
                <created>Sun, 13 Apr 2014 05:31:41 +0000</created>
                <updated>Wed, 10 Dec 2014 23:10:50 +0000</updated>
                            <resolved>Thu, 1 May 2014 21:20:43 +0000</resolved>
                                    <version>2.4.6</version>
                                                    <component>Index Maintenance</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="571077" author="thomasr" created="Fri, 2 May 2014 19:37:16 +0000"  >&lt;p&gt;Hi Abraham,&lt;/p&gt;

&lt;p&gt;You&apos;re right, it isn&apos;t well documented and can be confusing. I&apos;ll request a change in our documentation to make this clearer. Thanks for pointing that out.&lt;/p&gt;

&lt;p&gt;Regards,&lt;br/&gt;
Thomas&lt;/p&gt;</comment>
                            <comment id="571068" author="aplimovil" created="Fri, 2 May 2014 19:32:59 +0000"  >&lt;p&gt;Ok Thomas, I agree. However, I think it would be useful for other to specify this behavior on MongoDB&apos;s documentation, so they can expect indexes to not work on sorts on other columns when using geoNear.&lt;/p&gt;</comment>
                            <comment id="569891" author="thomasr" created="Thu, 1 May 2014 21:20:43 +0000"  >&lt;p&gt;Hi Abraham,&lt;/p&gt;

&lt;p&gt;I&apos;m going to close this issue now as we haven&apos;t heard back from you and I believe Asya replied to your question. If this does not match your scenario feel free to re-open the ticket and provide the additional information Asya requested.&lt;/p&gt;

&lt;p&gt;Regards,&lt;br/&gt;
Thomas&lt;/p&gt;</comment>
                            <comment id="547198" author="asya" created="Sun, 13 Apr 2014 08:35:20 +0000"  >&lt;p&gt;Since $near or $geoNear always return results ordered by distance from the point, it doesn&apos;t make sense to use them when you want results sorted by another field.&lt;/p&gt;

&lt;p&gt;If you want to sort by a different attribute you would need to use $geoWithin.  However, the index (assuming it&apos;s on geo, other field) cannot be used to sort the second field, only to filter by it.  This is a limitation of compound indexes when your use of the first field is not equality - the second field is not in order and has to be sorted.&lt;/p&gt;

&lt;p&gt;If what I described does not match your scenario, please show an example document, indexes on the collection and show an explain() for a query (find) with geoWithin and sort on another attribute also in the index.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="134673">DOCS-3338</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>4.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Sun, 13 Apr 2014 08:35:20 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        9 years, 41 weeks, 5 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>false</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>
                            9 years, 41 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>aplimovil</customfieldvalue>
            <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>thomas.rueckstiess@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrlwyv:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>112186</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;1. Take a big collection (more than 1,000,000 documents) with Points (geospatial data). Be sure a 2D or 2DSphere index is applied to the Point field.&lt;br/&gt;
2. Run a find() or aggregate() using geoNear or geoWithin, after which a sort() should be applied on an indexed field, after which a limit() should be set.&lt;br/&gt;
3. Run explain on the query above and you&apos;ll see the index is not used, as scanAndOrder=true and the number of scanned objects is very high.&lt;/p&gt;</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|hrj5bb:</customfieldvalue>

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