I'm trying to update messages in firebare (context: chat functionality) like for example in the following method.
markConversationAsSeen(conversationId: string, email: string) {
const messages = collection(this.firestore, 'messages');
const q = query(messages,
where('conversationId', '==' ,conversationId),
where('to', '==' , email),
where('seen', '==', false)
);
getDocs(q).then((documents) => {documents.forEach(document => {
const docId = document.id;
const ref = doc(this.firestore, `messages/${docId}`)
updateDoc(ref, { seen: true }).then();
})});
}
I think it's not optimal what I did ! Especially since the method first looks for the messages and then it updates them one by one (multi request to firebase)
Any suggestions please to enhance it ?
Thanks !