<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 07:37:47 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>[DOCS-31] Document how to write performant queries</title>
                <link>https://jira.mongodb.org/browse/DOCS-31</link>
                <project id="10380" key="DOCS">Documentation</project>
                    <description>&lt;p&gt;(Documentation written by Doug Green) Mongo uses btrees, and for the most part, indexes work the same in mongo as they do in mysql.  For most examples below assume an index on a,b,c.&lt;/p&gt;

&lt;p&gt; 1. The sort column must be the last column used in the index.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;good:&lt;/li&gt;
	&lt;li&gt;find(a=1).sort(a)&lt;/li&gt;
	&lt;li&gt;find(a=1).sort(b)&lt;/li&gt;
	&lt;li&gt;find(a=1,b=2).sort(c)&lt;/li&gt;
	&lt;li&gt;bad:&lt;/li&gt;
	&lt;li&gt;find(a=1).sort(c)&lt;/li&gt;
	&lt;li&gt;even though c is the last column in the index, a is that last column used, so you can only sort on a or b.&lt;br/&gt;
 1. The range query must also be the last column in an index, this is an axiom of 1 above.&lt;/li&gt;
	&lt;li&gt;good:&lt;/li&gt;
	&lt;li&gt;find(a=1,b&amp;gt;2)&lt;/li&gt;
	&lt;li&gt;find(a&amp;gt;1 and a&amp;lt;10)&lt;/li&gt;
	&lt;li&gt;find(a&amp;gt;1 and a&amp;lt;10).sort(a)&lt;/li&gt;
	&lt;li&gt;bad:&lt;/li&gt;
	&lt;li&gt;find(a&amp;gt;1, b=2)&lt;br/&gt;
 1. Only use a range query or sort on one column.&lt;/li&gt;
	&lt;li&gt;good:&lt;/li&gt;
	&lt;li&gt;find(a=1,b=2).sort(c)&lt;/li&gt;
	&lt;li&gt;find(a=1,b&amp;gt;2)&lt;/li&gt;
	&lt;li&gt;find(a=1,b&amp;gt;2 and b&amp;lt;4)&lt;/li&gt;
	&lt;li&gt;find(a=1,b&amp;gt;2).sort(b)&lt;/li&gt;
	&lt;li&gt;bad:&lt;/li&gt;
	&lt;li&gt;find(a&amp;gt;1,b&amp;gt;2)&lt;/li&gt;
	&lt;li&gt;find(a=1,b&amp;gt;2).sort(c)&lt;br/&gt;
 1. Conserve indexes by re-ordering columns used in straight = queries&lt;/li&gt;
	&lt;li&gt;If you have the following two queries, then you only need a single index, on a,b,d,c&lt;/li&gt;
	&lt;li&gt;find(a=1,b=1,d=1)&lt;/li&gt;
	&lt;li&gt;find(a=1,b=1,c=1,d=1)&lt;/li&gt;
	&lt;li&gt;When you need to sort this gets more difficult, and you might need two indexes&lt;br/&gt;
 1. Never use Mongo&apos;s $ne or $nin operator&apos;s&lt;/li&gt;
	&lt;li&gt;When excluding just a few documents, it&apos;s better to retrieve extra rows from Mongo and do the exclusion in php&lt;br/&gt;
 1. Never use Mongo&apos;s $exists operator&lt;/li&gt;
	&lt;li&gt;If you need to check for the existance of something, then you&apos;ll have to denormalize this value.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The doc is already in wiki notation so it must be easy to move.&lt;/p&gt;</description>
                <environment></environment>
        <key id="11792">DOCS-31</key>
            <summary>Document how to write performant queries</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="-1">Unassigned</assignee>
                                    <reporter username="chx">Karoly Negyesi</reporter>
                        <labels>
                    </labels>
                <created>Thu, 15 Apr 2010 14:18:58 +0000</created>
                <updated>Mon, 15 Aug 2011 19:11:57 +0000</updated>
                            <resolved>Fri, 16 Apr 2010 14:39:04 +0000</resolved>
                                                                        <due></due>
                            <votes>1</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="13696" author="kbanker" created="Fri, 16 Apr 2010 14:39:04 +0000"  >&lt;p&gt;Added to the doc minus the final recommendation on $exists.  If we can provide a clearer example, I think it&apos;d be worth adding.&lt;/p&gt;</comment>
                            <comment id="13668" author="rb2k" created="Thu, 15 Apr 2010 14:24:43 +0000"  >&lt;p&gt;If it doesn&apos;t exist and it is NOT a sparse index, it will be indexed as null.&lt;br/&gt;
So searching for non existant stuff can be done with a find for &quot;null&quot; on indexed fields&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>2.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Thu, 15 Apr 2010 14:24:43 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        13 years, 44 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>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>jess.mokrzecki@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            13 years, 44 weeks, 5 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>chx</customfieldvalue>
            <customfieldvalue>kbanker</customfieldvalue>
            <customfieldvalue>rb2k</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrsjhz:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>24145</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_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrynfj:</customfieldvalue>

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