I have a function designed to retrieve multiple documents from Firebase.
fetchDocuments(documentIds: string[]): Observable<TreeNodeDocument[]> {
const observables = [];
for(let id of documentIds){
observables.push(this.fetchDocument(id));
}
return Observable.combineLatest(observables, (...docs: TreeNodeDocument[]) => {
//perform some transformations on the retrieved documents
return docs;
});
}
The method this.fetchDocument(id)
returns an observable with type TreeNodeDocument
.
This function works well when all documents are successfully retrieved. However, sometimes it is possible that certain documents cannot be resolved, causing the corresponding fetchDocument(id)
observable to fail. While it is expected that some documents may not be retrievable, the Observable.combineLatest
fails altogether if any of them fail (which is the default behavior).
My question now is, can I use combineLatest
in a way that will only include the documents for which the retrieval was successful and disregard those that failed? Or is there another approach to achieve this?
Cheers