I have a database under firestore with the following structure:
-> Chat Room -> Users
I have a "ChatRoom" collection that contains a "Users" collection. In the users collection each document contains the field "read: true/false" in order to know if the user has read the messages that are in the room.
To retrieve the rooms of the current user I use this code:
getRoomFromUserId(userId: string) {
let rooms$: Observable<any>;
let rooms: AngularFirestoreCollection<any>;
rooms = this.afs.collection('ChatRoom', ref => {
return ref.where('Chatter.' + userId, '==', true);
});
rooms$ = rooms.snapshotChanges().map(changes => {
return changes.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return {id, ...data};
});
});
return rooms$;
}
To recover data from the "Users" subcollection I use this line of code:
this.afs.collection('ChatRoom').doc(RoomID).collection('Users').doc(UserId);
I'd like to retrieve an object that contains the room data and the "read: true/false" for each room I think it's possible with observables but I don't know how to do it. Do you have any ideas for a solution?