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?