With firestore, is it possible to configure offline persistence to set 'off' in a specific document?

会有一股神秘感。 提交于 2020-01-21 10:17:29

问题


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.



来源:https://stackoverflow.com/questions/52545182/with-firestore-is-it-possible-to-configure-offline-persistence-to-set-off-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!