Hi there!
I have an application which needs to do updates to some nested arrays. Following the mongoDB documentation, I have the following query:
const updatedDinner = await Dinner.findOneAndUpdate(
{ 'cups.plates': { $elemMatch: { id: plateId } } },
{
$set: {
updatedBy: 'me',
'cups.$[].plates.$[plate].status': 'COMPLETE',
'cups.$[].plates.$[plate].outputs':
finishedOutputs.map(formatOutput),
},
},
{
arrayFilters: [{ 'plate.id': plateId }],
new: true,
}
).exec();
This works MOST of the time, but every tenth or so time I don’t see the changes reflected in the database. The logs all look normal as if the update has gone through, but I just can’t see the change reflected in the database. any guidance would be much appreciated! Many thanks.
This is the data model:
const dinnerSchema = new mongoose.Schema(
{
id: {
type: String,
default: uuidV4,
index: true,
},
updatedBy: String,
cups: [
{
plates: [
{
id: {
type: Number,
index: true,
},
status: String,
outputs: [],
},
],
},
],
},
{
timestamps: true,
}
);