Trying to update element by id = 1234567890 and id= 8888888888 and .. (bulk) inside nested array es in the example below
{
"name": "template",
"process": [
{
"identifier": "process1",
"steps": [
{
"identifier": "step1",
"sections": [
{
"identifier": "section1",
"wrappers": [
{
"id: ": "000000000",
"item": {
"internalId": "00000001",
"name": "q1",
}
},
{
"id: ": "1234567890",
"item": {
"internalId": "00000002",
"name": "q2",
"question": "why"
},
"answer": "**update answer here**"
}
]
}
]
}
]
}
]
}
So far I tried to do like but unfortunately this syntax not acceptable :
db.collection.update(
{ "process.$.steps.$.sections.$.wrappers.id": "1234567890" },
{ "$set": { "process.$.steps.$.sections.$.wrappers.answer": "my answer fooo XXX " } }
)
I prefer using bulk , and also working with java - spring mongo data
please suggest
Maybe a bit ugly but it works
A bit more meaningful variant:
Mongo Playground: https://mongoplayground.net/p/yQyDBN7y2N7
And finally - Bulk Write:
A minor thing, but you have a typo in your example data,
idhas extract double quote and semicolon -"id: "