'how to get changes in a firestore document array of object
I have a collection called chats, I want to listen on the document for changes in the msg while also returning the data from the msg field, I have come up with a query but I am not getting the result I want. below is the code.
getCurrentMsgs(chatId){
return this.firestore.collection('chats', ref => ref.where('id', '==', chatId))
.snapshotChanges()
.pipe(
map(actions => {
return actions.map(a => {
// eslint-disable-next-line @typescript-eslint/ban-types
const data: Object = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
}
);
})
);
}
Solution 1:[1]
The snapshot received from listeners will always contains data of that whole document. You'll have to compare existing document data and the newly received update to get the changes in array. Packages like deep-object-diff might be useful in this case.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

