To update elements of a mongo array, I was using syntax like:
{"$set":{"a.0":1238},{"a.1":402}}
Or, more accurately, I was using the C-driver function calls that I think are equivalent to that. This seemed to work fine, but when I look at the object in MongoHub, I see:
a: {"0":1238,"1":402}
instead of:
a: [1238,402]
Does anyone know what is proper syntax to access array elements by index with C-driver? What I am doing now serves my immediate purpose, but I am not sure if there are significant performance differences. Also, I might later need to use operations that require true array.
If a field didn’t exist, then this dot-notation query will create it as a hash (object) and assign values to keys of that hash. If field exists and is an array, it will behave as you expect. See this session.