Note: This is not related to questions asking for how to update a field value to another field's value, because those do not include array filter matches.
I have the following query:
db.UserNotifications.updateOne(
{_id:ObjectId("5c5c39e94c9d4404d4577e94")},
{$set:{
"Notifications.$[match].Group.ActualUnreadCount": 50,
"Notifications.$[match].Group.UnreadCountSnapshot": "Notifications.$[match].Group.ActualUnreadCount"
}},
{arrayFilters:[{
"match.Group.Id": "some-id"
}]});
Now, what I wanted to do with this is set the value of UnreadCountSnapshot
for the match in the array, to the value of the ActualUnreadCount
of the same match.
Instead, UnreadCountSnapshot
just gets set to the string "Notifications.$[match].Group.ActualUnreadCount"
.
Any ideas on how to implement this?
Here's a sample document in the collection:
{
"_id": {
"$oid": "5c5c39e94c9d4404d4577e94"
},
"Notifications": [{
"Object": {
"_id": "5e3967cc9fc5720001d7100f",
"Type": "Transaction"
},
"Change": {
"Verb": "Create",
"TimeUtc": {
"$date": "2020-02-04T12:47:08.796Z"
},
"Actors": []
},
"Group": {
"TotalCount": 2,
"ActualUnreadCount": 50,
"UnreadCountSnapshot": 23,
"ReadTimeUtc": {
"$date": "2020-08-26T10:24:32.602Z"
},
"ViewTimeUtc": {
"$date": "2020-08-26T10:24:32.602Z"
}
}
}],
"LastNotificationTimeUtc": {
"$date": "2019-02-21T10:18:57.456Z"
},
"LastDeletedNotificationTimeUtc": {
"$date": "2020-08-26T10:24:30.374Z"
}
}