<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:23:32 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-10577] Updating sub document with positional operator </title>
                <link>https://jira.mongodb.org/browse/SERVER-10577</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;Please find my mongodb version details as follows.&lt;/p&gt;

&lt;p&gt;db version v2.2.2, pdfile version 4.5&lt;br/&gt;
Tue Aug 20 15:15:26 git version: d1b43b61a5308c4ad0679d34b262c5af9d664267&lt;/p&gt;

&lt;p&gt;Problem:&lt;/p&gt;

&lt;p&gt;let&apos;s say i have student collection and inserting the value as follows.&lt;/p&gt;

&lt;p&gt;db.students.insert( &lt;/p&gt;
{ 
&quot;_id&quot; : 4,
 &quot;grades&quot; : [ 
{ grade: 80, mean: 75, std: 8 }
&lt;p&gt;,&lt;/p&gt;
{ grade: 85, mean: 90, std: 5 }
&lt;p&gt;,&lt;/p&gt;
{ grade: 85, mean: 90, std: 5 }
&lt;p&gt;,&lt;/p&gt;
{ grade: 85, mean: 95, std: 6 }
&lt;p&gt;,&lt;/p&gt;
{ grade: 90, mean: 85, std: 5 } 
&lt;p&gt;] &lt;br/&gt;
}&lt;br/&gt;
);&lt;/p&gt;

&lt;p&gt;i&apos;ve one requirement where i want to update all the sub documents which is having id=4, grades.grade=85 and grades.std=5&lt;/p&gt;

&lt;p&gt;so following is my update statement which i am executing multiple times because &quot;$&quot; operator works only for first matching sub document.&lt;/p&gt;

&lt;p&gt;db.students.update( {&apos;$and&apos;:[ &lt;/p&gt;
{ _id: 4}
&lt;p&gt;,&lt;/p&gt;
{ &quot;grades.grade&quot;: 85 }
&lt;p&gt;, &lt;/p&gt;
{&quot;grades.std&quot;: 5 }
&lt;p&gt; ]}, { $set: &lt;/p&gt;
{ &quot;grades.$.std&quot; : 6 }
&lt;p&gt; } );&lt;/p&gt;

&lt;p&gt;But instead of updating 2nd &amp;amp; 3rd subdocument only , its applying &quot;or&quot; condition like either grades.grade = 85 or grades.std = 5 &lt;/p&gt;

&lt;p&gt;The Last sub document also getting updated.I feel its bug.Correct me if i am wrong.&lt;/p&gt;</description>
                <environment>Ubuntu 12.10,</environment>
        <key id="86624">SERVER-10577</key>
            <summary>Updating sub document with positional operator </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="david.hows">David Hows</assignee>
                                    <reporter username="mayurck291">Mayur Kataria</reporter>
                        <labels>
                            <label>update</label>
                    </labels>
                <created>Tue, 20 Aug 2013 10:09:11 +0000</created>
                <updated>Mon, 11 Jul 2016 17:38:18 +0000</updated>
                            <resolved>Tue, 22 Oct 2013 00:54:51 +0000</resolved>
                                    <version>2.2.2</version>
                                                    <component>Write Ops</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="444327" author="david.hows" created="Tue, 22 Oct 2013 00:54:51 +0000"  >&lt;p&gt;Thanks Mayur,&lt;/p&gt;

&lt;p&gt;As you have resolved this issue I&apos;m marking this ticket as closed.&lt;/p&gt;

&lt;p&gt;Regards,&lt;br/&gt;
David&lt;/p&gt;</comment>
                            <comment id="443667" author="mayurck291" created="Mon, 21 Oct 2013 06:05:42 +0000"  >&lt;p&gt;Thanks David,&lt;/p&gt;

&lt;p&gt;I&apos;ve already solved the same. The problem is as end user, i thought of applying simple update query &lt;br/&gt;
           db.students.update( {&apos;$and&apos;:[ &lt;/p&gt;
{ _id: 4}
&lt;p&gt;,&lt;/p&gt;
{ &quot;grades.grade&quot;: 85 }
&lt;p&gt;,&lt;/p&gt;
{&quot;grades.std&quot;: 5 }
&lt;p&gt;]}, { $set:{ &quot;grades.$.std&quot; : 6 }} );&lt;/p&gt;

&lt;p&gt;It&apos;s not mentioned in the document for update that &quot;while using Update &amp;amp; &apos;and&apos; condition you should use $elemMatch in case of subdocument.&quot; &lt;/p&gt;

&lt;p&gt;As end user, i thought like that.&lt;/p&gt;</comment>
                            <comment id="443656" author="david.hows" created="Mon, 21 Oct 2013 05:17:14 +0000"  >&lt;p&gt;Hi Mayur,&lt;/p&gt;

&lt;p&gt;You should use the &lt;a href=&quot;http://docs.mongodb.org/manual/reference/operator/query/elemMatch/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;$elemMatch operator&lt;/a&gt;, this will allow you to match a specific sub-document with multiple criteria, rather than one criteria. Eg&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;db.students.update({ _id: 4, grades: { $elemMatch:{ grade: 85, std: 5} }},{$set : {&quot;grades.$.std&quot;: 6}});&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;Does this fit your usecase?&lt;/p&gt;

&lt;p&gt;Regards,&lt;br/&gt;
David&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>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 21 Oct 2013 05:17:14 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            10 years, 17 weeks, 2 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </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>david.hows</customfieldvalue>
            <customfieldvalue>mayurck291</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrmiwn:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>79407</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;db.students.remove();&lt;/p&gt;

&lt;p&gt;db.students.insert( { &quot;_id&quot; : 4, &quot;grades&quot; : [ &lt;/p&gt;
{ grade: 80, mean: 75, std: 8 }
&lt;p&gt;,&lt;br/&gt;
                          &lt;/p&gt;
{ grade: 85, mean: 90, std: 5 }
&lt;p&gt;,&lt;br/&gt;
                          &lt;/p&gt;
{ grade: 85, mean: 90, std: 5 }
&lt;p&gt;,&lt;br/&gt;
                          &lt;/p&gt;
{ grade: 85, mean: 95, std: 6 }
&lt;p&gt;,&lt;br/&gt;
                          &lt;/p&gt;
{ grade: 90, mean: 85, std: 5 }
&lt;p&gt; ] });&lt;/p&gt;


&lt;p&gt;db.students.update( {&apos;$and&apos;:[ &lt;/p&gt;
{ _id: 4}
&lt;p&gt;,&lt;/p&gt;
{ &quot;grades.grade&quot;: 85 }
&lt;p&gt;, &lt;/p&gt;
{&quot;grades.std&quot;: 5 }
&lt;p&gt; ]}, { $set: &lt;/p&gt;
{ &quot;grades.$.std&quot; : 6 }
&lt;p&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|hspckv:</customfieldvalue>

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