Deleted Firestore documents still being retrieved

前端 未结 2 1706
盖世英雄少女心
盖世英雄少女心 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 01:58

    Probably you have the problem, that the app uses the cache and loads as well some documents from it. One thing you could try is to disable the offline persistence.

    If you're using Android with Real-Time Database you could try this:

    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    

    iOS + Real-Time Database

    Database.database().isPersistenceEnabled = true
    

    If you're using FireStore then use the following:

    Android:

    FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
            .setPersistenceEnabled(false)
            .build();
    db.setFirestoreSettings(settings);
    

    iOS:

    let settings = FirestoreSettings()
    settings.isPersistenceEnabled = false
    
    // Any additional options
    // ...
    
    // Enable offline data persistence
    let db = Firestore.firestore()
    db.settings = settings
    
    0 讨论(0)
  • 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<T>[]) => {
              return actions
                .filter((a: DocumentChangeAction<T>) => a.payload.doc.exists)
                .map((a: DocumentChangeAction<T>) => {
                  const data: T = {...a.payload.doc.data() as {}} as T;
                  data['id'] = a.payload.doc.id;
                  return data;
                });
            })
          );
    
    0 讨论(0)
提交回复
热议问题