<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 06:07:06 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-67030] `$getField` doesn&apos;t work with a dynamic `field`</title>
                <link>https://jira.mongodb.org/browse/SERVER-67030</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;&#160;&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;db.test.insert({ a: &apos;a&apos; });&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;db.test.aggregate([{ $addFields: { result: { $getField: { field: { $concat: [&apos;$a&apos;, &apos;a&apos;] }, input: { aa: 1 } } } } }]);&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;This leads to:&lt;/p&gt;

&lt;p&gt;&#160;&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;MongoServerError: Invalid $addFields :: caused by :: $getField requires &apos;field&apos; to evaluate to a constant, but got a non-constant argument&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;I don&apos;t understand why that happens (and believe it&apos;s a bug). According to &lt;a href=&quot;https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;getField&apos;s documentation&lt;/a&gt; `field` can be any expression that resolves to a string. In my example it is such but it doesn&apos;t work.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</description>
                <environment></environment>
        <key id="2062531">SERVER-67030</key>
            <summary>`$getField` doesn&apos;t work with a dynamic `field`</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="13202">Works as Designed</resolution>
                                        <assignee username="anton.korshunov@mongodb.com">Anton Korshunov</assignee>
                                    <reporter username="alien">Boris Petrov</reporter>
                        <labels>
                    </labels>
                <created>Mon, 6 Jun 2022 11:26:58 +0000</created>
                <updated>Fri, 27 Oct 2023 13:52:00 +0000</updated>
                            <resolved>Tue, 21 Jun 2022 15:35:52 +0000</resolved>
                                    <version>5.0.9</version>
                                                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="4631417" author="alien" created="Wed, 22 Jun 2022 07:48:19 +0000"  >&lt;p&gt;&lt;a href=&quot;https://feedback.mongodb.com/forums/924280-database/suggestions/45337738--getfield-to-work-with-a-dynamic-field&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Done&lt;/a&gt;!&lt;/p&gt;</comment>
                            <comment id="4629630" author="JIRAUSER1265262" created="Tue, 21 Jun 2022 16:34:03 +0000"  >&lt;p&gt;Thank you Anton for clarification on that! I didn&apos;t catch the constant part of the field description.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=alien&quot; class=&quot;user-hover&quot; rel=&quot;alien&quot;&gt;alien&lt;/a&gt;, in this case, you can actually go ahead and go to &lt;a href=&quot;https://feedback.mongodb.com/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;feedback.mongodb.com&lt;/a&gt; to submit this as a feature request if you like. Thanks for your report!&lt;/p&gt;

&lt;p&gt;Christopher&lt;/p&gt;</comment>
                            <comment id="4629469" author="alien" created="Tue, 21 Jun 2022 15:59:38 +0000"  >&lt;p&gt;Anton, thank you for the information! I didn&apos;t expect &quot;constant&quot; to literally mean constant at &quot;compile&quot; time as that&apos;s perhaps the only place in MongoDB&apos;s query language where such a restriction exists. It would be nice if it is lifted at some point (even with a performance-penalty). I guess you can change this ticket to be a feature-request one instead of a bug. &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;Thanks again for the time!&lt;/p&gt;</comment>
                            <comment id="4629370" author="anton.korshunov" created="Tue, 21 Jun 2022 15:35:37 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=alien&quot; class=&quot;user-hover&quot; rel=&quot;alien&quot;&gt;alien&lt;/a&gt; The &lt;tt&gt;$getField&lt;/tt&gt; expression in this particular examples works as designed. Note that our documentation says:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Field in the input object for which you want to return a value. field can be any valid expression that resolves to a string &lt;b&gt;constant&lt;/b&gt;.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;So, the &lt;tt&gt;input&lt;/tt&gt; argument must resolve to a constant string. It can be any arbitrary expression as soon as it folds into a string literal. For example, &lt;tt&gt;$concat: &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;&amp;#93;&lt;/span&gt;&lt;/tt&gt; is a valid argument, as it can be folded into &lt;tt&gt;&quot;ab&quot;&lt;/tt&gt; during the query optimization phase. While &lt;tt&gt;$concat: &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;$a&amp;quot;, &amp;quot;a&amp;quot;&amp;#93;&lt;/span&gt;&lt;/tt&gt; can only be evaluated in runtime, since it contains a field path expression &lt;tt&gt;&quot;$a&quot;&lt;/tt&gt; to extract field &lt;tt&gt;&quot;a&quot;&lt;/tt&gt; from the input document. Runtime arguments are not supported by the &lt;tt&gt;$getField&lt;/tt&gt; expression as the name of the field we&apos;re accessing should be known to the optimizer at compile time.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=chris.kelly%40mongodb.com&quot; class=&quot;user-hover&quot; rel=&quot;chris.kelly@mongodb.com&quot;&gt;chris.kelly@mongodb.com&lt;/a&gt; With regards to this note about the &lt;tt&gt;$literal expression&lt;/tt&gt;. It pertains to a scenario when you need to access a field in a document which starts with the &lt;tt&gt;$&lt;/tt&gt; symbol, as in &lt;tt&gt;$getField: &quot;$a&quot;&lt;/tt&gt;. The parser will treat &lt;tt&gt;&quot;$a&quot;&lt;/tt&gt; as a field path expression and fail with an error like in the description to this ticket. A correct way to extract the field &lt;tt&gt;$a&lt;/tt&gt; would be: &lt;tt&gt;$getField: {$literal: &quot;$a&quot;&lt;/tt&gt;}.&lt;/p&gt;

&lt;p&gt;I&apos;m going to close this ticket as &quot;Works as designed&quot;.&lt;/p&gt;</comment>
                            <comment id="4627926" author="JIRAUSER1265262" created="Tue, 21 Jun 2022 04:22:01 +0000"  >&lt;p&gt;Hi Boris,&lt;/p&gt;

&lt;p&gt;Thanks for your report. I was able to reproduce your issue on MongoDB 5.0.9 and am inclined to agree that this shouldn&apos;t have an error. Specifically, there seems to be a &lt;a href=&quot;https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/#syntax&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;note about something similar already:&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If&#160;&lt;tt&gt;field&lt;/tt&gt;&#160;begins with a dollar sign (&lt;tt&gt;$&lt;/tt&gt;), place the field name inside of a&#160;&lt;a href=&quot;https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;&lt;tt&gt;$literal&lt;/tt&gt;&lt;/a&gt;&#160;expression to return its value.&lt;/p&gt;

&lt;p&gt;I tried using $literal in $getField as well to see if we could get around it that way, but I&apos;m still having the same issue you reported.&lt;/p&gt;

&lt;p&gt;I&apos;ll go ahead and forward this to the Query Execution team for further investigation.&#160;&lt;/p&gt;

&lt;p&gt;Christopher&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="2274943">SERVER-74371</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>5.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 21 Jun 2022 04:22:01 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        1 year, 33 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_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>luke.bonanomi@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            1 year, 33 weeks 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>anton.korshunov@mongodb.com</customfieldvalue>
            <customfieldvalue>alien</customfieldvalue>
            <customfieldvalue>chris.kelly@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i0xk1j:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i0gfjc:</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_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>
                                    <customfieldvalue><![CDATA[chris.kelly@mongodb.com]]></customfieldvalue>
    

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i0x66v:</customfieldvalue>

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