<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 05:21:33 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-50041] Preserve field order between $set clause and updated document</title>
                <link>https://jira.mongodb.org/browse/SERVER-50041</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Using { $set:{ b:1, a:1 } } for updating results in { a:1, b:1 }.&lt;/p&gt;

&lt;p&gt;If I use older version like mongodb 3.4.0, the result will be { b:1, a:1 }.&lt;/p&gt;</description>
                <environment>mongodb 4.0.4</environment>
        <key id="1425460">SERVER-50041</key>
            <summary>Preserve field order between $set clause and updated document</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="12300">Won&apos;t Do</resolution>
                                        <assignee username="bernard.gorman@mongodb.com">Bernard Gorman</assignee>
                                    <reporter username="mysyljr@gmail.com">&#20426;&#20161; &#26753;</reporter>
                        <labels>
                            <label>qexec-team</label>
                    </labels>
                <created>Fri, 31 Jul 2020 13:25:46 +0000</created>
                <updated>Mon, 30 Nov 2020 16:14:45 +0000</updated>
                            <resolved>Mon, 30 Nov 2020 16:14:45 +0000</resolved>
                                                                    <component>Querying</component>
                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="3508481" author="bernard.gorman" created="Mon, 30 Nov 2020 16:13:57 +0000"  >&lt;p&gt;This change is a consequence of the update system modernization work undertaken in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-28621&quot; title=&quot;Parse BSON update expression into an UpdateNode tree&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-28621&quot;&gt;&lt;del&gt;SERVER-28621&lt;/del&gt;&lt;/a&gt;, which was part of the broader &quot;Array Updates&quot; project in 3.6. As Eric outlined above, a &lt;tt&gt;$set&lt;/tt&gt; statement is simply a series of directives about which fields to update with what values, but the order of fields in the &lt;tt&gt;$set&lt;/tt&gt; does not guarantee the order of creation of the relevant fields if they do not already exist in the input document. The fact that this happened prior to 3.6 was simply an implementation detail of the previous update system. Under the new system, output documents will be generated consistently for all equivalent input &lt;tt&gt;$set&lt;/tt&gt; statements. In view of this, I&apos;m going to close this ticket as Won&apos;t Do.&lt;/p&gt;

&lt;p&gt;Note, finally, that it &lt;b&gt;is&lt;/b&gt; possible to define the order in which fields are added into a document, by using pipeline-style updates to encode the desired field ordering as part of the request:&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;replset:PRIMARY&amp;gt; db.testing.insert({_id: 0})&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;WriteResult({ &quot;nInserted&quot; : 1 })&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;replset:PRIMARY&amp;gt; db.testing.update({_id: 0}, [{$set: {c: 2}}, {$set: {a: 1}}])&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;WriteResult({ &quot;nMatched&quot; : 1, &quot;nUpserted&quot; : 0, &quot;nModified&quot; : 1 })&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;replset:PRIMARY&amp;gt; db.testing.find()&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;{ &quot;_id&quot; : 0, &quot;c&quot; : 2, &quot;a&quot; : 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;</comment>
                            <comment id="3335138" author="eric.sedor" created="Wed, 12 Aug 2020 18:29:45 +0000"  >&lt;p&gt;To clarify, it is not currently true that the order of fields in a JSON or BSON document implies the order of creation of those fields.&lt;/p&gt;

&lt;p&gt;If tracking the order of updates to documents in such a way is necessary for your use-case, we recommend encoding that information explicitly.&lt;/p&gt;

&lt;p&gt;It&apos;s worth noting that the order of fields in queries as written can also be changed when queries defined in language-native data types (JSON in JavaScript, Dict in Python, etc.) are serialized to BSON for transmission to the server.&lt;/p&gt;

&lt;p&gt;I&apos;m going to pass this request on to an appropriate team for consideration.&lt;/p&gt;</comment>
                            <comment id="3324060" author="JIRAUSER1254547" created="Thu, 6 Aug 2020 07:36:07 +0000"  >&lt;p&gt;Like this:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Field order means the order of creation of that field, so&#160;field order just&#160;&lt;b&gt;matters.&lt;/b&gt;&lt;/li&gt;
	&lt;li&gt;Updating a document&#160; {a:1, c:1} with {&lt;tt&gt;$set:{a:2,b:1&lt;/tt&gt;}} results in&#160; {a:2, c:1, b:1}. Fine.&lt;/li&gt;
	&lt;li&gt;Updating a document&#160; {a:1, c:1} with {&lt;tt&gt;$set:{c:2,a:1&lt;/tt&gt;}} results in&#160; {a:1, c:2}. Fine.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;But:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Updating a document { } with {&lt;tt&gt;$set:{c:2,a:1&lt;/tt&gt;}} results in {a:1, c:2}. Not Fine. {c:2,a:1} is wanted&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;My problem is order &lt;b&gt;matters&lt;/b&gt; when creating new fields, which seems to be impossible now.&#160;&lt;/p&gt;</comment>
                            <comment id="3323074" author="eric.sedor" created="Wed, 5 Aug 2020 16:54:24 +0000"  >&lt;p&gt;Can you clarify:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;what is the document field order logically telling the application?&lt;/li&gt;
	&lt;li&gt;what field order does your use require when updating a document {&lt;tt&gt;a:1, c:1&lt;/tt&gt;} with {&lt;tt&gt;$set:{a:2,b:1&lt;/tt&gt;}}?&lt;/li&gt;
	&lt;li&gt;what about {&lt;tt&gt;a:1, c:1&lt;/tt&gt;} receiving {&lt;tt&gt;$set:{c:2,a:1&lt;/tt&gt;}}?&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;This information will help us understand the requirements and may help us suggest workarounds.&lt;/p&gt;</comment>
                            <comment id="3321708" author="JIRAUSER1254547" created="Wed, 5 Aug 2020 03:21:00 +0000"  >&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;I need to add two more fields to a document with certain order in only one update op, which seems to be impossible without this improvement or bugfix.&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="3321396" author="eric.sedor" created="Tue, 4 Aug 2020 21:30:20 +0000"  >&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;Order of fields &lt;b&gt;within&lt;/b&gt; documents is handled &lt;a href=&quot;https://docs.mongodb.com/manual/core/document/#document-field-order&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;as described here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But this does not apply to the order of fields in a $set clause at all. We&apos;d consider this an improvement rather than a bug.&lt;/p&gt;

&lt;p&gt;If you&apos;d like to see MongoDB support such a guarantee can you describe your use-case and explain how you&apos;d like to see $set order handled in situations where fields exist in the document in a different order than in the $set?&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Eric&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>6.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18555" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname># of Sprints</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>Tue, 4 Aug 2020 21:30:20 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        3 years, 10 weeks, 2 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>bernard.gorman@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            3 years, 10 weeks, 2 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>bernard.gorman@mongodb.com</customfieldvalue>
            <customfieldvalue>eric.sedor@mongodb.com</customfieldvalue>
            <customfieldvalue>mysyljr@gmail.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hxxjnz:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hx5c53:</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_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="3620">Query 2020-11-30</customfieldvalue>
    <customfieldvalue id="3621">Query 2020-12-14</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>
                                    <customfieldvalue><![CDATA[eric.sedor@mongodb.com]]></customfieldvalue>
    

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

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