Reputation: 4610
I have a document with this structure:
{
codeId: 1,
generatedCodes: [
{
name: 'Code 1',
status: 'In Progress'
},
{
name: 'Code 2',
status: 'In Progress'
},
{
name: 'Code 3',
status: 'In Progress'
}
]
}
I'm trying to update the status
property of each object by using the following code:
db.codes.update({codeId: id}, {$set: {'generatedCodes.$[].status': 'Validated'}}, {multi: true})
But none of the array items get the new status
...
Upvotes: 0
Views: 73
Reputation: 278
i just run the following and it worked:
db.getCollection('yourCollection').update({codeId: 1}, {$set: {'generatedCodes.$[].status': 'Validated'}}, {multi: true})
the only difference from your code is that i changed {codeId: id} to {codeId: 1}
so make sure you are passing the correct id.
Upvotes: 1