Deleted Firestore documents still being retrieved

前端 未结 2 1707
盖世英雄少女心
盖世英雄少女心 2021-01-14 01:29

I have deleted some documents through a batch delete from a trigger in Cloud Functions. The console shows them as being deleted, however, my app still retrieves the docs! Th

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-14 02:01

    Documents remain fetchable for a while after deletion. Their existence status rely on the DocumentSnapshot property - 'exists' and can be read and filtered in the pipe with snapshotChanges() method for docs and collections. See the example below:

    ...
    .snapshotChanges()
          .pipe(
            map((actions: DocumentChangeAction[]) => {
              return actions
                .filter((a: DocumentChangeAction) => a.payload.doc.exists)
                .map((a: DocumentChangeAction) => {
                  const data: T = {...a.payload.doc.data() as {}} as T;
                  data['id'] = a.payload.doc.id;
                  return data;
                });
            })
          );
    

提交回复
热议问题