<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:07:27 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-13309] MongoDB does not guarantee short circuit evaluation and it should not be mentioned</title>
                <link>https://jira.mongodb.org/browse/DOCS-13309</link>
                <project id="10380" key="DOCS">Documentation</project>
                    <description>&lt;h2&gt;&lt;a name=&quot;Description&quot;&gt;&lt;/a&gt;Description&lt;/h2&gt;
&lt;p&gt;These pages:&lt;br/&gt;
&lt;a href=&quot;https://docs.mongodb.com/manual/reference/operator/query/and/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.com/manual/reference/operator/query/and/&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;https://docs.mongodb.com/manual/reference/operator/aggregation/and/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.com/manual/reference/operator/aggregation/and/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;mention that&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;The $and operator uses short-circuit evaluation. If the first expression (e.g. &amp;lt;expression1&amp;gt;) evaluates to false, MongoDB will not evaluate the remaining expressions.&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;$and uses short-circuit logic: the operation stops evaluation after encountering the first false expression.&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Although there is a kernel of truth here and $and does perform short-circuit evaluation for performance, the query system is free to change the order of predicates inside a $and. In fact the find query system currently sorts all of them in an order that&apos;s arbitrary to the user in find. Agg performs some reordering in unusual circumstances.&lt;/p&gt;

&lt;p&gt;In general the query system must be free to reorder predicates as it sees fit during optimization and the order it chooses may change when MongoDB is upgraded or due to other factors.&lt;/p&gt;

&lt;p&gt;When the order is changed, the user will not get the short-circuit evaluation they specified in the query.&lt;/p&gt;

&lt;p&gt;I&apos;ve opened a ticket to track a request for a way to optionally define predicate evaluation order: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-45231&quot; title=&quot;Provide a way to cause a well-defined order of evaluation for predicates&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-45231&quot;&gt;&lt;del&gt;SERVER-45231&lt;/del&gt;&lt;/a&gt;. But for now it should be emphasized that there is no way to guarantee the order no matter what the query system empirically seems to be doing today. Following from this, we cannot guarantee that unnecessary $and expressions are evaluated or not evaluated at all. Also if a runtime error would occur due to the evaluation of an expression in a $and, we cannot guarantee it will or will not occur.&lt;/p&gt;

&lt;p&gt;This is true for find and aggregation and for predicates listed outside of a $and within a find query. If we&apos;re defensive about it in the docs we can prevent customer surprise later.&lt;/p&gt;

&lt;h2&gt;&lt;a name=&quot;Scopeofchanges&quot;&gt;&lt;/a&gt;Scope of changes&lt;/h2&gt;

&lt;h2&gt;&lt;a name=&quot;ImpacttoOtherDocs&quot;&gt;&lt;/a&gt;Impact to Other Docs&lt;/h2&gt;

&lt;h2&gt;&lt;a name=&quot;MVP%28WorkandDate%29&quot;&gt;&lt;/a&gt;MVP (Work and Date)&lt;/h2&gt;

&lt;h2&gt;&lt;a name=&quot;Resources%28ScopeorDesignDocs%2CInvision%2Cetc.%29&quot;&gt;&lt;/a&gt;Resources (Scope or Design Docs, Invision, etc.)&lt;/h2&gt;
</description>
                <environment></environment>
        <key id="1059618">DOCS-13309</key>
            <summary>MongoDB does not guarantee short circuit evaluation and it should not be mentioned</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="jason.price@mongodb.com">Jason Price</assignee>
                                    <reporter username="jacob.evans@mongodb.com">Jacob Evans</reporter>
                        <labels>
                    </labels>
                <created>Wed, 18 Dec 2019 17:09:56 +0000</created>
                <updated>Mon, 30 Oct 2023 20:29:51 +0000</updated>
                            <resolved>Wed, 1 Sep 2021 21:33:52 +0000</resolved>
                                                    <fixVersion>Server_Docs_20231030</fixVersion>
                                    <component>manual</component>
                    <component>Server</component>
                        <due></due>
                            <votes>1</votes>
                                    <watches>9</watches>
                                                                                                                <comments>
                            <comment id="4035181" author="xgen-internal-githook" created="Wed, 1 Sep 2021 20:37:46 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;jason-price-mongodb&apos;, &apos;email&apos;: &apos;jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-13309&quot; title=&quot;MongoDB does not guarantee short circuit evaluation and it should not be mentioned&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-13309&quot;&gt;&lt;del&gt;DOCS-13309&lt;/del&gt;&lt;/a&gt; short circuit evaluation&lt;br/&gt;
Branch: v4.0&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/f6269067996c89f23cf3d3018fec780a4eade2bd&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/f6269067996c89f23cf3d3018fec780a4eade2bd&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4035178" author="xgen-internal-githook" created="Wed, 1 Sep 2021 20:37:35 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;jason-price-mongodb&apos;, &apos;email&apos;: &apos;jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-13309&quot; title=&quot;MongoDB does not guarantee short circuit evaluation and it should not be mentioned&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-13309&quot;&gt;&lt;del&gt;DOCS-13309&lt;/del&gt;&lt;/a&gt; short circuit evaluation&lt;br/&gt;
Branch: v4.2&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/c25fac557742e725722e0e94c48d610260b7f185&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/c25fac557742e725722e0e94c48d610260b7f185&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4035045" author="xgen-internal-githook" created="Wed, 1 Sep 2021 19:56:59 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;jason-price-mongodb&apos;, &apos;email&apos;: &apos;jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-13309&quot; title=&quot;MongoDB does not guarantee short circuit evaluation and it should not be mentioned&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-13309&quot;&gt;&lt;del&gt;DOCS-13309&lt;/del&gt;&lt;/a&gt; short circuit evaluation&lt;br/&gt;
Branch: v4.4&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/da267b6a15b1bc0b2c6253a9ff1c80f9863149fb&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/da267b6a15b1bc0b2c6253a9ff1c80f9863149fb&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4035025" author="xgen-internal-githook" created="Wed, 1 Sep 2021 19:47:09 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;jason-price-mongodb&apos;, &apos;email&apos;: &apos;jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-13309&quot; title=&quot;MongoDB does not guarantee short circuit evaluation and it should not be mentioned&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-13309&quot;&gt;&lt;del&gt;DOCS-13309&lt;/del&gt;&lt;/a&gt; short circuit evaluation&lt;br/&gt;
Branch: v5.0&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/4b16e2c3a5f841b264a68edf0b3ba148fd12cc50&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/4b16e2c3a5f841b264a68edf0b3ba148fd12cc50&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4034819" author="xgen-internal-githook" created="Wed, 1 Sep 2021 18:31:25 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;jason-price-mongodb&apos;, &apos;email&apos;: &apos;jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-13309&quot; title=&quot;MongoDB does not guarantee short circuit evaluation and it should not be mentioned&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-13309&quot;&gt;&lt;del&gt;DOCS-13309&lt;/del&gt;&lt;/a&gt; short circuit evaluation&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/1c2026123f568b99fd7ca41a8ab50f40149be5ff&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/1c2026123f568b99fd7ca41a8ab50f40149be5ff&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3593922" author="charlie.swanson" created="Tue, 2 Feb 2021 00:13:11 +0000"  >&lt;p&gt;Just wanted to ping again on this - it came up again in the context of&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-52619&quot; title=&quot;Performance Regression on 4.4 compared to 4.2 on Aggregate query&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-52619&quot;&gt;&lt;del&gt;SERVER-52619&lt;/del&gt;&lt;/a&gt; recently.&lt;/p&gt;</comment>
                            <comment id="2710314" author="charlie.swanson" created="Tue, 7 Jan 2020 18:23:00 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=bduncan%40visualmining.com&quot; class=&quot;user-hover&quot; rel=&quot;bduncan@visualmining.com&quot;&gt;bduncan@visualmining.com&lt;/a&gt; the expression language also does not have any such guarantees. To the extent that it works today, it is only because the optimizer isn&apos;t sophisticated enough to do any transformations or reorderings to it. I think &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-37530&quot; title=&quot;Provide a way to cause a well-defined order of evaluation for predicates&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-37530&quot;&gt;SERVER-37530&lt;/a&gt; should remain as the ticket requesting any guaranteed order of evaluation, there is no such concept today - it just may happen to work out that way.&lt;/p&gt;</comment>
                            <comment id="2691062" author="bduncan@visualmining.com" created="Sun, 29 Dec 2019 21:23:01 +0000"  >&lt;p&gt;I would argue that the documentation should also address short-circuit evaluation within the expression language accessible using `$expr`.&#160; To my knowledge, reordering does not happen within those expressions and so the user specified order is retained and thereby any benefit they were counting on from short-circuit evaluation.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="616200">SERVER-37530</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1533409">SERVER-52619</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1059612">SERVER-45231</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="1051885">SERVER-45123</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>8.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Sun, 29 Dec 2019 21:23:01 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        2 years, 23 weeks 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_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>DOCSP-11701</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_14873" key="com.atlassian.jira.plugin.system.customfieldtypes:multiuserpicker">
                        <customfieldname>External Reviewer</customfieldname>
                        <customfieldvalues>
                                    <customfieldvalue><![CDATA[jacob.evans@mongodb.com]]></customfieldvalue>
    
                        </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>emet.ozar@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            2 years, 23 weeks ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>bduncan@visualmining.com</customfieldvalue>
            <customfieldvalue>charlie.swanson@mongodb.com</customfieldvalue>
            <customfieldvalue>xgen-internal-githook</customfieldvalue>
            <customfieldvalue>jacob.evans@mongodb.com</customfieldvalue>
            <customfieldvalue>jason.price@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hwc1un:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="5359">ServerDocs2021: Aug10 - Aug17</customfieldvalue>
    <customfieldvalue id="5397">ServerDocs2021: Aug17 - Aug24</customfieldvalue>
    <customfieldvalue id="5414">ServerDocs2021: Aug24 - Aug31</customfieldvalue>
    <customfieldvalue id="5439">ServerDocs2021: Aug31 - Sep07</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10555" key="com.atlassian.jira.plugin.system.customfieldtypes:float">
                        <customfieldname>Story Points</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>3.0</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|hwbo3z:</customfieldvalue>

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