Lets say you are in pipeline and you have this
$$mydoc = one document
$$mykey = one key
How to do
(and all those basic operation on maps that programming languages offer)
I had the same problems before sometime,in mongodb for now seems that the key can’t be in a variable.
The problem is not just the 10 lines,but object to array and back to object,is so slow to be done multiple times(for example hen reducing a array to a document).
I didn’t got any solution yet,i dont think its possible.
I managed to implement fast only put,and only if the key is new.
But if the you keep the documents with known fields (known schema),you can use unwind/group/project
etc , and if you want to do those for an embeded data,you can use facet,and do those.
If you know where to send this either to be answered or to ask to be added on mongoDB ,would be nice.
Yeah this is exactly what I’m wondering. Too bad that there doesn’t seem to be a (better) way. :-/
In my case the fields are not known in advance, but there are not too many of them (1-100), so I hope the approach I wrote using $objectToArray and back will be fast enough when the number of fields is at the upper limit.