Re: discontiguous array index keys

From: Asya Kamsky <asya@xxxxxxxxxxx>
To: "mongodb-user@xxxxxxxxxxxxxxxx" <mongodb-user@xxxxxxxxxxxxxxxx>
Date: Thu, 21 Apr 2016 01:12:50 -0400
Why ads?
It looks like you ran into
https://jira.mongodb.org/browse/CDRIVER-504

It's possible for it to cause a subtle access issue - glad you found a
workaround to fixing them.

Would you mind adding a comment with your description of the problem to the
Jira ticket?   It'll help prioritize it knowing that more people have run
into it.

Asya

On Monday, April 18, 2016, <tim.dorcey@xxxxxxxxx> wrote:

I just discovered that I have been inserting documents that contain arrays
whose elements are indexed with odd numbers only. E.g., document looks like
{_id:1,a:[100,200,300]}
but array element keys are "1","3","5".  e.g., db.find({'a:5':300})
returns the document while db.find({'a:2':300}) does not.
This is possible because the C-driver takes a key value when you append
array elements to a bson object you are building.  It is supposed to be
"0", "1", "2".... but I have accidentally been using "1","3","5",...
without any apparently harm, unless I try to refer to a specific array
element with dot notation as in above examples.  Then it does remember what
index key was used on insertion, though I am not sure how to see that in
the database, or what happens after updates.

I have been adding new elements with {$push:{a:{$each:[400,500]}}} where
the $each array is indexed with "1" and "3".  Does that mean I get index
keys [1,3,5,1,3] or maybe [1,3,5,6,8] or [1,3,5,6,7] or [0,1,2,3,4]?

For the most part, I never refer to the indices, and did not even realize
the database was saving them.  I load an array, and then use the
"bson_iter_next" to walk through the elements.  I think all of my updates
using $push:$each or "$addToSet:$each have been working correctly.
Assuming I never need to refer to a specific element with dot notation, is
there any reason I need to repair these index keys for proper array
management?



--
You received this message because you are subscribed to the Google Groups
"mongodb-user"
group.

For other MongoDB technical support options, see:
https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx
<javascript:_e(%7B%7D,'cvml','mongodb-user%2Bunsubscribe@xxxxxxxxxxxxxxxx');>
.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx
<javascript:_e(%7B%7D,'cvml','mongodb-user@xxxxxxxxxxxxxxxx');>.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/1e44f511-3c9d-4445-92d3-02fc71fe0a3b%40googlegroups.com
<https://groups.google.com/d/msgid/mongodb-user/1e44f511-3c9d-4445-92d3-02fc71fe0a3b%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.



-- 
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers

-- 
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
--- 
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOe6dJAHBZumTfe-oW20z12R_JmbGbqTfVCQA-B-Mb9Z6v251Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Why ads?