I have a function that needs to resolve 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[]) => {
//some transformations on the resolved documents
return docs;
});
}
this.fetchDocument(id) returns an observable of type TreeNodeDocument.
This function works as long as all of the documents can be resolved. Now sometimes it happens that some of the documents cannot be resolved, then the respective fetchDocument(id) observable will fail. It is ok and expected that some of the documents cannot be resolved. However the Observable.combineLatest fails completely if one of them fails (I understand this is a good default behaviour).
My question is now, can I use combineLatest in a way so I get only the documents on which the fetch has worked and just ignore the ones on which it failed? Or can I achieve this in a different way?
Cheers