With firestore, is it possible to configure offlin

2020-04-01 05:10发布

问题:

I need to set off the persistence in a certain document in Firestore; but all other documents should work with default configuration like this implementation. I have implemented the code; but calling firestoreSettings again causing this error in below:

java.lang.IllegalStateException: FirebaseFirestore has already been started and its settings can no longer be changed. You can only call setFirestoreSettings() before calling any other methods on a FirebaseFirestore object. at com.google.firebase.firestore.FirebaseFirestore.setFirestoreSettings(com.google.firebase:firebase-firestore@@17.0.5:140)

How can I achieve to set setPersistenceEnabled=false for a specific document or is it possible? Thanks in advance.

回答1:

Disk persistence can only be enabled for the entire Firestore client, before performing any other operations. It cannot be enabled/disabled for specific collections, queries or documents.



回答2:

The way offline persistence works is by synchronizing the current state of each document written while offline. It doesn't synchronize the entire history of all the writes. The history of writes is irrelevant - what matters is only the current values in the document. Therefore, enabling persistence is not as expensive as you might be expecting.

As Frank said, you can't selectively choose to synchronize only some documents. It's either entirely off or on. Personally, I don't think you have a compelling case to disable it.