<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:10:13 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-5908] update push override the last element</title>
                <link>https://jira.mongodb.org/browse/SERVER-5908</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I wrote a lua driver(&lt;a href=&quot;https://github.com/bigplum/lua-resty-mongol&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/bigplum/lua-resty-mongol&lt;/a&gt;) based on openresty(ngx_lua) project. There is an issue: &lt;a href=&quot;http://forum.nginx.org/read.php?2,226716,226744#msg-226744&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://forum.nginx.org/read.php?2,226716,226744#msg-226744&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1. use lua-resty-mongol inster an embeded array, mongo shell shows ok. &lt;br/&gt;
The &quot;undefined&quot; value comes from that lua table index beginning from 1.&lt;/p&gt;

&lt;p&gt;  local t = {}&lt;br/&gt;
  table.insert(t,&lt;/p&gt;
{a = &quot;aa&quot;}
&lt;p&gt;)&lt;br/&gt;
  table.insert(t,&lt;/p&gt;
{b = &quot;bb&quot;}
&lt;p&gt;)&lt;br/&gt;
  r, err = col:insert(&lt;tt&gt;name=&quot;dog&quot;,n=&quot;10&quot;,tab=t&lt;/tt&gt;, nil, true)&lt;/p&gt;

&lt;p&gt;&amp;gt; db.test.find()&lt;br/&gt;
{ &quot;_id&quot; : ObjectId(&quot;4fbc97e10853d55c767302f8&quot;), &quot;tab&quot; : [ undefined, &lt;/p&gt;
{ &quot;a&quot; : &quot;aa&quot; }
&lt;p&gt;, &lt;/p&gt;
{ &quot;b&quot; : &quot;bb&quot; }
&lt;p&gt; ], &quot;name&quot; : &quot;dog&quot;, &quot;n&quot; : &quot;10&quot; }&lt;/p&gt;

&lt;p&gt;2. use mongo shell update to push a new value into tab, the last element of tab is overrided.&lt;/p&gt;

&lt;p&gt;&amp;gt; db.test.update(&lt;/p&gt;
{name:&quot;dog&quot;}
&lt;p&gt;, {$push:{tab:&quot;a5&quot;}})&lt;br/&gt;
&amp;gt; db.test.find()&lt;br/&gt;
{ &quot;_id&quot; : ObjectId(&quot;4fbc97e10853d55c767302f8&quot;), &quot;n&quot; : &quot;10&quot;, &quot;name&quot; : &quot;dog&quot;, &quot;tab&quot; : [ undefined, &lt;/p&gt;
{ &quot;a&quot; : &quot;aa&quot; }
&lt;p&gt;, &quot;a5&quot; ] }&lt;/p&gt;

&lt;p&gt;So, is this bug is related with the &quot;undefined&quot; value?&lt;/p&gt;</description>
                <environment>ubuntu 12.04&lt;br/&gt;
&lt;br/&gt;
Linux simon-1 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux&lt;br/&gt;
</environment>
        <key id="39419">SERVER-5908</key>
            <summary>update push override the last element</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</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="2">Won&apos;t Fix</resolution>
                                        <assignee username="benjamin.becker">Ben Becker</assignee>
                                    <reporter username="bigplum">Simon</reporter>
                        <labels>
                            <label>update</label>
                    </labels>
                <created>Wed, 23 May 2012 08:01:48 +0000</created>
                <updated>Fri, 7 Mar 2014 00:24:32 +0000</updated>
                            <resolved>Mon, 18 Jun 2012 23:56:05 +0000</resolved>
                                    <version>2.0.4</version>
                                                    <component>Internal Code</component>
                    <component>Write Ops</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="134181" author="bigplum" created="Tue, 19 Jun 2012 01:46:29 +0000"  >&lt;p&gt;Hi Ben Becker&lt;/p&gt;

&lt;p&gt;Thanks for the comments. I&apos;ve modify the driver to pack index 0 into the BSON string as I commented at May 25.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/bigplum/lua-resty-mongol/commit/e1594ca019a655b14a843267abd3a5905b69fefa&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/bigplum/lua-resty-mongol/commit/e1594ca019a655b14a843267abd3a5905b69fefa&lt;/a&gt; &lt;/p&gt;</comment>
                            <comment id="134169" author="benjamin.becker" created="Mon, 18 Jun 2012 23:56:05 +0000"  >&lt;p&gt;Simon,&lt;/p&gt;

&lt;p&gt;Please feel free to reopen this issue if you have further questions/concerns.  Also, feel free to open a new issue to add more robust array index verification to the server.&lt;/p&gt;</comment>
                            <comment id="134168" author="benjamin.becker" created="Mon, 18 Jun 2012 23:54:02 +0000"  >&lt;p&gt;Hi Simon,&lt;/p&gt;

&lt;p&gt;The issue with inserting an undefined value into an array was indeed due to the array index difference you mentioned.  The BSON spec requires keys be in ascending numeric order, but the logic in to_bson() does not enforce this.  &lt;/p&gt;

&lt;p&gt;You may want to consider changing bson.lua ~L188, which checks for a zero-based array, and simply enforce 0-based sequential array values in this function.  I believe from_bson()/read_document() will need a similar translation to ensure table indices start at 1.  IIRC, the luamongo driver takes a similar approach (see bson_to_array() and lua_append_bson() in utils.cpp).&lt;/p&gt;

&lt;p&gt;Regarding the behavior where $push&apos;ing a value overwrites the last array value when an &apos;undefined&apos; value is present, this definitely seems undesirable.  That being said, the issue is due to array indexing of malformed BSON, and the behavior technically makes sense when you consider the original array indexes are off by one.&lt;/p&gt;

&lt;p&gt;We could add a check for the index base, but full verification of the array index sequence could be expensive.  Ideally the driver should enforce array index order at creation time (as the driver needs to build the BSON array anyway).&lt;/p&gt;

&lt;p&gt;     Best Regards,&lt;br/&gt;
     Ben&lt;/p&gt;</comment>
                            <comment id="133478" author="siddharth.singh@10gen.com" created="Fri, 15 Jun 2012 21:08:51 +0000"  >&lt;p&gt;Hi Simon,&lt;/p&gt;

&lt;p&gt; Can you please send your lua test script, the one that you used to repro this bug.&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;</comment>
                            <comment id="133466" author="siddharth.singh@10gen.com" created="Fri, 15 Jun 2012 20:49:49 +0000"  >&lt;p&gt;I am not sure using the lua driver will help but I am willing to give it a try. The effect of using the lua driver is only with regards to Step 1, where it enters an undefined value to the array. In my script, at the end of line 4, the array looks exactly the way it would if I were using the lua driver. Step 2 (where you actually see the override behavior) is performed from the mongo shell anyways so I don&apos;t think it should affect anything.&lt;/p&gt;

&lt;p&gt;Anyways, I will update the issue after I have tried it with the lua driver.&lt;/p&gt;</comment>
                            <comment id="131423" author="bigplum" created="Wed, 13 Jun 2012 01:33:37 +0000"  >&lt;p&gt;JS array index is begining from 0, so the js script could not reproduce this issue. You should try the lua driver.&lt;/p&gt;</comment>
                            <comment id="131128" author="siddharth.singh@10gen.com" created="Tue, 12 Jun 2012 16:30:06 +0000"  >
&lt;p&gt; I checked both against the 2.0.4 version and the current master and $push seems to work correctly. I used the mongo shell and then followed the same steps as you outlined in the ticket. To be really sure I verified both with the &apos;undefined&apos; and &apos;null&apos; values. I have attached a script that you can try as well. &lt;/p&gt;
</comment>
                            <comment id="130708" author="bigplum" created="Tue, 12 Jun 2012 02:00:23 +0000"  >&lt;p&gt;The latest version of lua-resty-mongol has fixed this issue. But I think may be a bug in mongodb kernel. I can pack an old version to reproduce this issue.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/downloads/bigplum/lua-resty-mongol/lua-resty-mongol.80cd614a4e.tar.gz&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/downloads/bigplum/lua-resty-mongol/lua-resty-mongol.80cd614a4e.tar.gz&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="130494" author="siddharth.singh@10gen.com" created="Mon, 11 Jun 2012 19:29:27 +0000"  >&lt;p&gt;Hi Simon,&lt;/p&gt;

&lt;p&gt;  I just tested push with array values and it works fine. Not sure what you meant when you said &quot;is this bug is related with the &quot;undefined&quot; value?&quot; Was it an issue with your driver that you patched ? Can you please confirm.&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;</comment>
                            <comment id="122970" author="bigplum" created="Fri, 25 May 2012 01:21:40 +0000"  >&lt;p&gt;I&apos;ve patched my driver, add tab&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;=nil into the LUA array. So the insert operation would produce a null value instead of &quot;undefined&quot; value. &lt;/p&gt;

&lt;p&gt;{ &quot;_id&quot; : ObjectId(&quot;4fbc97e10853d55c767302f8&quot;), &quot;tab&quot; : [ null, &lt;/p&gt;
{ &quot;a&quot; : &quot;aa&quot; }
&lt;p&gt;, &lt;/p&gt;
{ &quot;b&quot; : &quot;bb&quot; }
&lt;p&gt; ], &quot;name&quot; : &quot;dog&quot;, &quot;n&quot; : &quot;10&quot; }&lt;/p&gt;

&lt;p&gt;And the push issue is also fixed now.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="17148" name="5908.js" size="847" author="siddharth.singh@10gen.com" created="Tue, 12 Jun 2012 16:30:23 +0000"/>
                            <attachment id="17321" name="bug.lua" size="356" author="siddharth.singh@10gen.com" created="Mon, 18 Jun 2012 17:43:45 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>10.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 11 Jun 2012 19:29:27 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            11 years, 35 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>benjamin.becker</customfieldvalue>
            <customfieldvalue>siddharth.singh@10gen.com</customfieldvalue>
            <customfieldvalue>bigplum</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hro267:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>23031</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>
                                

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

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