Now the issue is I am failing to produce the same behaviour using pipeline style update statements. Can someone advice on how to achieve this behaviour with a pipeline style update. Many thanks in Advance.
I would like to use pipelines, because there is no way of removing an item from an array in an atomic way based on its index without using pipelines (at least upto my [limited] knowledge).
Me and my colleagues try to implement patching (RFC 6902). This allows removing and altering at the same time (given it works on different arrays), so we’d like to get it to work.
What determines that you want element 1 of top_level and element 1 of second_level?
If the index is determined by other field of the array, then you are better off using arrayFilters rather than indexes.
For example if you want to update top_level.1.second_level.1 because top_level.1.name is 3 and the corresponding second_level.1.surname is 5 then specifying arrayFilters should work.
With indexes rather than arrayFilters, something like the following might work:
Basically, we are using a monogDB behind a run-of-the-mill CRUD API. So which index to manipulate is given by the outside patch request. There are workaround solutions, yes. All these break the atomicity bar yours potentially. I had hoped that there was an easy implementation in mongo query language, as the standard JSON patching is so similar to the general document structure in a MongoDB.
Thank you for your answer. I will try it out. Anyhow, it becomes rather involved the more nested lists you amass. Will have to think about this.