<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 04:40: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-35739] Object Constructor methods like ObjectId, UUID, Date do not work with a field parameter value with $addFields </title>
                <link>https://jira.mongodb.org/browse/SERVER-35739</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;ol&gt;
	&lt;li&gt;I want to update the equivalent of a foreign key field that has an ObjectId string value with the ObjectId itself. I have tried using the aggregation $addFields and have discovered that ObjectId(&quot;$hexStringField&quot;) errors with:&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Failed to execute script. &lt;/p&gt;

&lt;p&gt;Error: invalid object id: length :&lt;br/&gt;
@(shell):2:26&lt;/p&gt;


&lt;ol&gt;
	&lt;li&gt;I suspected that there might be a problem using Object constructor methods so I tried using $addFields with UUID(&quot;$uuidStringField&quot;) and Date(&quot;$dateField&quot;).&lt;br/&gt;
Using these methods did not produce an error, but did not give the expected results.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;&#160;&lt;/p&gt;</description>
                <environment></environment>
        <key id="562869">SERVER-35739</key>
            <summary>Object Constructor methods like ObjectId, UUID, Date do not work with a field parameter value with $addFields </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="nick.brewer">Nick Brewer</assignee>
                                    <reporter username="ensefik">Edem Nsefik</reporter>
                        <labels>
                    </labels>
                <created>Fri, 22 Jun 2018 10:16:13 +0000</created>
                <updated>Tue, 14 Aug 2018 03:02:42 +0000</updated>
                            <resolved>Tue, 17 Jul 2018 14:56:19 +0000</resolved>
                                    <version>3.6.5</version>
                                                    <component>Aggregation Framework</component>
                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="1949115" author="nick.brewer" created="Tue, 17 Jul 2018 14:56:07 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=ensefik&quot; class=&quot;user-hover&quot; rel=&quot;ensefik&quot;&gt;ensefik&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This can be accomplished with the new &lt;a href=&quot;https://docs.mongodb.com/manual/release-notes/4.0/#new-type-conversion-operators&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;type conversion operators&lt;/a&gt; introduced in MongoDB 4.0.&lt;/p&gt;

&lt;p&gt;Nick&lt;/p&gt;</comment>
                            <comment id="1928749" author="nick.brewer" created="Fri, 22 Jun 2018 14:55:02 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=ensefik&quot; class=&quot;user-hover&quot; rel=&quot;ensefik&quot;&gt;ensefik&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;it ignores the hex string and instead generates a value that seems to be based on the name of the field and not the value in the field&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Can you provide an example of this behavior?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Using these methods did not produce an error, but did not give the expected results.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;What results did you receive? &lt;/p&gt;

&lt;p&gt;In general, it would be useful to get the specific commands you&apos;re running (including UUIDs, dates, etc), as well as the output you&apos;re receiving. &lt;/p&gt;

&lt;p&gt;Thanks, &lt;br/&gt;
Nick&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>Fri, 22 Jun 2018 14:55:02 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        5 years, 30 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>backlog-server-pm</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            5 years, 30 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>ensefik</customfieldvalue>
            <customfieldvalue>nick.brewer</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hu17en:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hts0fz:</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;ol&gt;
	&lt;li&gt;The following code example executed in a Mongo shell does not work properly&lt;br/&gt;
I am trying to create the ObjectId of string field someId into field newId:&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;db.collection1.aggregate([&lt;br/&gt;
&#160; {$addFields: {newId: ObjectId(&quot;$someId&quot;)}}, &lt;br/&gt;
&#160; &#160;{$out: &quot;collection1&quot; }&lt;br/&gt;
])&lt;/p&gt;


&lt;ol&gt;
	&lt;li&gt;If in the above code I replace ObjectId and someId with:&lt;br/&gt;
a.) UUID and a field with a UUID hex string - it ignores the hex string and instead generates a value that seems to be based on the name of the field and not the value in the field&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;b) Date and a field with a date - it generates the same date value ignoring the date value in the field&#160;&lt;/p&gt;


&lt;ol&gt;
	&lt;li&gt;&#160;The equivalent code which works and doesn&apos;t use aggregation works:&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;db.coll1.find().forEach(function(results){&lt;br/&gt;
&#160; print( &quot;fileId: &quot; + results.fileId );&lt;br/&gt;
&#160; try {&lt;br/&gt;
&#160; &#160; db.coll1.update( {_id : results._id, someId: {$type: &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;string&amp;quot;&amp;#93;&lt;/span&gt;}},&#160;&lt;br/&gt;
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;{$set: &lt;/p&gt;
{newId: ObjectId(results.someId)}
&lt;p&gt;&#160;})&#160;&lt;br/&gt;
 &#160;} catch (err) &lt;/p&gt;
{
&#160; &#160; print(err.name + &apos;: &quot;&apos; + err.message + &apos;&quot; occurred using someId &apos;+ results.someId +&quot;.&quot;);
&#160; }
&lt;p&gt;})&lt;br/&gt;
newId is created as a new field with the ObjectId of the someId field&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|hu0tnz:</customfieldvalue>

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