Hi all,
I’m having strange problem with updateOne, probably because I’m fresh on MongoDB and I’m doing some rookie error
My collection looks like this:
{
_id: ObjectId(“628b3de8b94528801b9c50d0”),
name: ‘Piccolo’,
theatre: ‘Cinestar’,
rows: 2,
columns: 2,
seats: [
{ row: 0, col: 0, type: ‘X’ },
{ row: 1, col: 0, type: ‘X’ },
{ row: 0, col: 1, type: ‘X’ },
{ row: 1, col: 1, type: ‘X’ }
]
}
I want to be able to update property Type for every element inside seats array so I use this:
db.auditoriums.updateOne({_id: ObjectId(“628b3de8b94528801b9c50d0”), “seats.row”: 1, “seats.col”: 0},{$set: {“seats.$.type”: “Z”}})
and this works every time I change only row attribute. But if I change col attribute too it doesn’t match and doesn’t do any change.
{
acknowledged: true,
insertedId: null,
matchedCount: 1,
modifiedCount: 0,
upsertedCount: 0
}
What I’m doing wrong?