[SERVER-22053] Insertion of Array with undefined/null components. Created: 04/Jan/16  Updated: 08/Jan/24  Resolved: 04/Aug/16

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.2.0
Fix Version/s: 3.2.14, 3.3.11

Type: Bug Priority: Critical - P2
Reporter: Paul Reed Assignee: Waley Chen
Resolution: Done Votes: 0
Labels: bkp
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Duplicate
is duplicated by SERVER-1874 Arrays with undefined values silently... Closed
Related
related to SERVER-19376 Make SpiderMonkey the default JS Engine Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.2
Steps To Reproduce:

Previously to 3.2 when this happened

var s = []
s[1] = 1
print(s) => [ undefined, 1]
db.colll.insert(

{mys:s}

)

you would get a doc like this:

{ mys: [ null, 1] }

now in v3.2 you get this document:

{ mys: [1] }

So the data has shifted up an index.

Is this a new BUG or an old BUG fixed - cannot find any reference to it elsewhere.

====

fyi:
It has played havoc with some of my Map Reductions which rely on the specific placement of values in an array against a standard header array which I use to populate the array i.e.
value.arr[ header.indexOf( this.term ) ] = this.avalue;
emit(..., value)

I think that there might be an insert between the map and reduction where the array is restructured.

Sprint: Platforms 18 (08/05/16)
Participants:
Linked BF Score: 0

 Description   

Inserts of arrays with undefined/null content in positions are being treated differently in version 3.2.



 Comments   
Comment by Githook User [ 04/May/17 ]

Author:

{u'username': u'WaleyChen', u'name': u'Waley Chen', u'email': u'waleycz@gmail.com'}

Message: SERVER-22053 Insertion of Array with undefined/null components

(cherry picked from commit af198512c7dbb00442fb5115aeac661bf85535c8)

lint fix
(cherry picked from commit 9c3c7d8328d50d45206d310d5c63f0197f49ab39)
Branch: v3.2
https://github.com/mongodb/mongo/commit/a9e694a18f25775764c9ef110a6ad6fcdc30569d

Comment by Githook User [ 04/Aug/16 ]

Author:

{u'username': u'WaleyChen', u'name': u'Waley Chen', u'email': u'waleycz@gmail.com'}

Message: SERVER-22053 Insertion of Array with undefined/null components

lint fix
Branch: master
https://github.com/mongodb/mongo/commit/9c3c7d8328d50d45206d310d5c63f0197f49ab39

Comment by Githook User [ 04/Aug/16 ]

Author:

{u'username': u'WaleyChen', u'name': u'Waley Chen', u'email': u'waleycz@gmail.com'}

Message: SERVER-22053 Insertion of Array with undefined/null components
Branch: master
https://github.com/mongodb/mongo/commit/af198512c7dbb00442fb5115aeac661bf85535c8

Comment by Kelsey Schubert [ 27/Jan/16 ]

Hi paul.reed,

Sorry for the delay publicly responding. We have identified that this bug was introduced by the switch from V8 to SpiderMonkey as the default JS engine (SERVER-19376). The fix is scheduled to be included in the 3.4 release, and I have requested a backport of this fix to 3.2 branch as well. Please continue to watch this ticket for updates.

Thank you for the clear reproduction steps,
Thomas

Comment by Paul Reed [ 26/Jan/16 ]

Any news this?

Comment by Paul Reed [ 04/Jan/16 ]

Just checked and it is only when an item is undefined that the array is truncated. Nulls get passed correctly

[ undefined, 1 ] inserts to [1]
[ null, 1 ] inserts to [ null, 1 ]

Generated at Thu Feb 08 03:59:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.