I would like to know if it's possible to detect when a new fields is added on a document with cloud functions. I store all my friends in a single document with this structure :
- userId
- friends_sub_collection
- friendsListDocument
friendId0 (HashMap<String, Object>)
"status": "friend_request",
"date" : 1583448203,
...
friendId1
friendId2
...
I know that i can get the changes in cloud functions with something like :
.onUpdate((change, context) => {
const newValue = change.after.data();
const previousValue = change.before.data();
}
But since my fields are documentId i can't check if they exists with something like newValue.friendsFieldId
My suggestion will be to store all ids in an array of the document allFriendsId
, then check the difference between the old and new array and then get the right field.
Is there any better ways ?
Thanks for the suggestions and your time.