Let's say I have a document in a Mongo database that looks like this:
{ pages: [ { elements: [ {id:1}, {id:2}, {id:3} ] }, { elements: [ ... ] } ] }
and that the order of elements within a page has semantic meaning (e.g., stacking). Now say that I want to add a new element before the second element on the first page. The desired state of the resulting document is as follows:
{ pages: [ { elements: [ {id:1}, {id:4},
In Mongo docs, I see how to add elements to the end of an array and how to update the value of an existing element, but not how to insert in the middle of an array (à la PHP array_splice ). Is this possible only by reassigning the entire array to a new array with the desired element inserted in the middle?
source share