I have a user model something like this
{
_id:"something",
email:"[email protected]",
contacts:[
{_id:"123",status:"PENDING"},
{_id:"456",status:"PENDING"},
{_id:"789",status:"PENDING"}
]
}
And I have an id of one of the user’s contacts "123" and I want to update that specific contact’s status from "PENDING" to "SUCCESSFUL". How can I do that?
2
Answers
Easiest way is with the array identifier $, like so:
Mongo Playground
The array identifier updates the first element of the array that matches the query.