I am trying show array data from collection and filter it by sub collection data.
Here is the collection
Here for the sub-collection
How to list and grouping all user with date from subcollection (chat).
The result array like this
- id
- name
- message (last message)
- read
- date (last chat time)
do i need create new collection for store all data?
I have tring with this code.
Can not show the data when looping it
getChats() {
let users: any = [];
return this.chatService.getUsers().pipe(
switchMap((res: any) => {
users = res;
return this.firestore
.collection('user')
.doc(this.idUser)
.collection('chat', (ref) => ref.orderBy('date'))
.valueChanges({ idField: 'id' }) as Observable<Message[]>;
}),
map((messages) => {
for (let m of messages) {
m.name = this.getUserForMsg(m.id, users);
m.read = this.idUser === m.dc001frommsg;
}
return messages;
})
);
}
(await this.getChats()).subscribe((data) => {
this.listChat = data;
}))
in Html
<ul *ngFor="let user of listChats">
<li (click)="detail(user)"> {{ user.name }}</li>
</ul>
question from:
https://stackoverflow.com/questions/65599120/get-data-sub-collection-and-grouping-by-parent-collection-firebase-angular-9 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…