I have a structure like this and in this I want to update the role of userId '2' to "Admin".
{
"chats": {
"chatThreadID": {
"chatUsers": [
{
"userId": 1,
"role": "Admin"
},
{
"userId": 2,
"role": "General"
},
{
"userId": 3,
"role": "General"
}
]
}
}
}
I tried doing 'updateData'
"chatUsers": FieldValue.arrayRemove([oldUser.dictionary])
Then
"chatUsers": FieldValue.arrayUnion([updatedUser.dictionary])
This works, but is there any better way to do this?