Is there a way to keep the link in the same collection, but reorder it with firestore?
TL; DR: This is similar to the functionality that I am trying to achieve:
https://stackoverflow.com/a/1662616/169/121 , but since my data is received from firestore, I do not quite understand the correct way to do this dynamically.
Say I have messagesService.tsone that contains a collection of messages and a link to an Observable message:
messagesCollection: AngularFirestoreCollection<Message>
messages: Observable<Message[]>;
this.messagesCollection = this.db.collection('messages', ref => {
return ref.orderBy('dateCreated', 'desc');
});
this.messages= this.messagesCollection.valueChanges();
When I insert this data into *ngFor="let message of messages | async", it displays the most recent posts on top, as expected.
Where do I need help:
( , firestore). , , , , , .. , ? , ?
- :
sortMessagesBy(field) {
this.messagesCollection = this.db.collection('messages', ref => {
return ref.orderBy(field, 'desc');
});
}
, , , , .
, :
sortMessagesBy(field) {
this.messagesCollection = this.db.collection('messages', ref => {
return ref.orderBy(field, 'desc');
});
this.messages= this.messagesCollection.valueChanges();
return this.messages;
}
, , this.messages, ngFor ( trackBy).
,, , , where IE:
this.messagesCollection = this.db.collection('messages', ref => {
return ref.where("type", "==", "todo").orderBy(field, 'desc');
});
, , , .