I have a collection with an array like this inside of if (array lengths vary)
"arrayName": [
{"name": "D", "_id": ObjectId(IDOFD)},
{"name": "C", "_id": ObjectId(IDOFC)},
{"name": "B", "_id": ObjectId(IDOFB)},
{"name": "A", "_id": ObjectId(IDOFA)}
]
im trying to replace all the values before a certain element in that array - say I want to replace every element before the element with "_id": ObjectId(IDOFB) (if the element with this id is the last element of the array just push the "replacementValues" array after the specified element) with:
"replacementValues": [
{"name": "REPLACE 1", "_id": ObjectId(IDOFREPLACE 1)},
{"name": "REPLACE 2", "_id": ObjectId(IDOFREPLACE 2)}
]
this will result in:
"arrayName": [
{"name": "D", "_id": ObjectId(IDOFD)},
{"name": "C", "_id": ObjectId(IDOFC)},
{"name": "B", "_id": ObjectId(IDOFB)},
{"name": "REPLACE 1", "_id": ObjectId(IDOFREPLACE 1)},
{"name": "REPLACE 2", "_id": ObjectId(IDOFREPLACE 2)}
]
how can I achieve this? Any help would be greatly appreciated!