I am interacting with a mongodb through Javascript.
Is there any difference between the following two statements?
myCollection.insert({tiles: new Int32Array(256)});
myCollection.insert({tiles: new Array(256)});
Yes, it's very different.
The first using Int32Array
, which isn't a JavaScript type that the current driver uses/understands, instead becomes projected into an object with properties following the indices of the array:
"tiles" : { "0" : 0, "1" : 0, "2" : 0.... }
The second translates to an Array in MongoDB, of type Null
.
"tiles": [ null, null, null .... ]
So, the first does not remain as an array, while the second one does.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.