<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:50: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>[SERVER-19387] Query validity not checked before execution</title>
                <link>https://jira.mongodb.org/browse/SERVER-19387</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I was executing the below query on the enron dataset provided as part of MongoDB university training.&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;   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;m101:PRIMARY&amp;gt; db.messages.aggregate([ {$unwind:&quot;$headers.To&quot;},  {$group:{_id:{id&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   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;: &apos;$_id&apos;, from:&apos;$headers.From&apos;}, to:{$addToSet: &apos;$headers.To&apos;}}}, {$unwind:&quot;$to&quot;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   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;}, {$project:{_id:0,from:&quot;$_id.from&quot;,to:1}}, {$group:{_id:{from:&quot;$from&quot;,to:&quot;$to&quot;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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-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;},count:{$sum:1}}}, {$sort:{&quot;count&quot;:-1}} ]).explain();&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;It came back after full 13 seconds complaining that there is a syntax errorL&lt;/p&gt;

&lt;p&gt;2015-07-14T05:59:44.438-0400 E QUERY    TypeError: Object #&amp;lt;Object&amp;gt; has no method &apos;explain&apos;&lt;br/&gt;
    at (shell):1:271&lt;br/&gt;
m101:PRIMARY&amp;gt;&lt;/p&gt;

&lt;p&gt;In my opinion validity of the query should be checked first before actually executing the query. Here it seems to have executed the query and then tried to execute the unavailable &quot;explain&quot; method which makes it look like an expensive mistake.&lt;/p&gt;

&lt;p&gt;Apologies if similar jira already exists or if this is filed under wrong project.&lt;/p&gt;</description>
                <environment></environment>
        <key id="216691">SERVER-19387</key>
            <summary>Query validity not checked before execution</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="sam.kleinman">Sam Kleinman</assignee>
                                    <reporter username="pratik229">Pratik Patel</reporter>
                        <labels>
                    </labels>
                <created>Tue, 14 Jul 2015 10:15:29 +0000</created>
                <updated>Tue, 14 Jul 2015 18:55:14 +0000</updated>
                            <resolved>Tue, 14 Jul 2015 15:24:14 +0000</resolved>
                                    <version>3.0.3</version>
                                                    <component>Usability</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="965974" author="pratik229" created="Tue, 14 Jul 2015 18:55:14 +0000"  >&lt;p&gt;Thank you!&lt;/p&gt;</comment>
                            <comment id="965834" author="samk" created="Tue, 14 Jul 2015 16:47:36 +0000"  >&lt;p&gt;Unfortunately the return type of JavaScript functions is not universally deducible before execution, and the language doesn&apos;t support that kind of error checking. You can connect to MongoDB instances with any driver, and while the shell is convenient for basic testing and exploration, there&apos;s no reason that you have to use a JavaScript environment and can easily use another driver and environment with more familiar semantics: consider the &lt;a href=&quot;http://docs.mongodb.org/ecosystem/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;full list of drivers&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;For MongoDB-related discussion you can post on the &lt;a href=&quot;http://groups.google.com/group/mongodb-user&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongodb-users group&lt;/a&gt; group&lt;br/&gt;
or &lt;a href=&quot;http://stackoverflow.com/questions/tagged/mongodb&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Stack Overflow with the &lt;tt&gt;mongodb&lt;/tt&gt; tag&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Regards,&lt;br/&gt;
sam&lt;/p&gt;</comment>
                            <comment id="965752" author="pratik229" created="Tue, 14 Jul 2015 15:43:08 +0000"  >&lt;p&gt;Thanks for the insight!&lt;/p&gt;

&lt;p&gt;I come from an SQL based database background where such errors would be flagged immediately, so hope you can understand why this behavior seemed strange to me!&lt;/p&gt;

&lt;p&gt;I of course don&apos;t want to re-open the issue given that I have recently started using MongoDB and don&apos;t have in depth understanding yet. But won&apos;t the return type of aggregate be a json document? Is it not possible for the shell (or any driver for that matter) to make a fair assumption about return types and enforce a check on syntax before approaching the server?&lt;/p&gt;

&lt;p&gt;Don&apos;t intend to frustrate you with my naive questions. Please let me know if I should take this discussion to a different Q&amp;amp;A type of forum.&lt;/p&gt;</comment>
                            <comment id="965714" author="samk" created="Tue, 14 Jul 2015 15:20:48 +0000"  >&lt;p&gt;The error you&apos;re seeing is an error in the JavaScript shell. The shell sees a method chain, where each method executes and then calls the next method on the result of the first method, and so on. So the &lt;tt&gt;.aggregate()&lt;/tt&gt; method executes, which takes 13 seconds in this case, and then pases its result to the &lt;tt&gt;.explain()&lt;/tt&gt; method, which it discovers at runtime does not exist. Because the return type of the &lt;tt&gt;.aggregate()&lt;/tt&gt; method isn&apos;t known until it returns, JavaScript and the Shell can&apos;t produce an error until after the function completes.&lt;/p&gt;

&lt;p&gt;I&apos;m sorry for the frustration, and hope that this explanation is useful. &lt;/p&gt;

&lt;p&gt;Regards,&lt;br/&gt;
sam&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="81746" name="enron.zip" size="113701880" author="pratik229" created="Tue, 14 Jul 2015 10:15:29 +0000"/>
                    </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>Tue, 14 Jul 2015 15:20:48 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        8 years, 31 weeks, 1 day 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>pratik229</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            8 years, 31 weeks, 1 day ago
                        </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>pratik229</customfieldvalue>
            <customfieldvalue>sam.kleinman</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrl0rb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hsb653:</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_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;Execute the following query on attached dataset (enron.zip):&lt;/p&gt;

&lt;p&gt;db.messages.aggregate([ &lt;br/&gt;
	{$unwind:&quot;$headers.To&quot;}, &lt;br/&gt;
	{$group:{_id:&lt;/p&gt;
{id: &apos;$_id&apos;, from:&apos;$headers.From&apos;}
&lt;p&gt;, to:{$addToSet: &apos;$headers.To&apos;}}},&lt;br/&gt;
	{$unwind:&quot;$to&quot;},&lt;br/&gt;
	{$project:{_id:0,from:&quot;$_id.from&quot;,to:1}},&lt;br/&gt;
	{$group:{_id:&lt;/p&gt;
{from:&quot;$from&quot;,to:&quot;$to&quot;}
&lt;p&gt;,count:{$sum:1}}},&lt;br/&gt;
	{$sort:{&quot;count&quot;:-1}}&lt;br/&gt;
]);&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|hrjakv:</customfieldvalue>

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