Reputation: 95
I have the following object stored in MongoDb. I am sending a messageRead
attribute inside my messages
array.
I have tried:
collection.updateOne({ '_id': ObjectId(employeeID) },
{
"$set": {
"userObject.messages.message.message_uuid" : { employeeMessageUpdateUUID, "messageRead" : employeeMessageRead }
}
but it does not work. I find the object i'm looking for through the _id
, and then try to find the message
using the message_uuid
however the messageRead
attribute is not updating. I am clearly using the wrong Mongo query.. What should my $set
look like?
Upvotes: 1
Views: 34
Reputation: 11975
You can use $ operator to do that:
collection.updateOne(
{
'_id': ObjectId(employeeID),
'userObject.messages.message.message_uuid': employeeMessageUpdateUUID
},
{
$set: { 'userObject.messages.$.message.messageRead': employeeMessageRead }
}
)...
Upvotes: 1