android - Data on Firestore console differs from the retrieved when consulting the database
问题描述
I deleted a document through firebase console, but then, when I run my project and it looks for that document, it retrieves the deleted document (that i can´t see in the console).
Firebase console showing there's no data saved in Cloud Firestore
Not sure if deleting the document is what triggered this problem.
Tried creating a new document with the same id, and see if then, the app would get this new document instead of the deleted one. There was no use, still bringing the deleted document.
It seems like the data used to display my collections and documents on the console, is not the same as the one that is consulted when running my project.
I reported this as a bug, but, has anyone experienced something similar?, how did you fix it?
解决方案
This is not a bug. The Firestore client SDKs have a feature called offline persistence that is enabled by default in Android and iOS. This feature caches your data so your app can access it even if the device is offline.
You can specify the data source for a query by passing a source argument to the get()
method.
documentReference.get(Source.SERVER)
// or
query.get(Source.SERVER)
if you are using a SnapshotListener and the document exists in cache, the first result will always come from the cache. You can check it by doing this:
documentReference.addSnapshotListener(MetadataChanges.INCLUDE) { snap, e ->
snap?.metadata?.isFromCache
}
推荐阅读
- python - 在 pyspark 中加入两个数据帧会导致“检测到隐式笛卡尔积”错误
- java - 如何绕过或不调用在另一个方法内部调用的方法
- reactjs - 直接从客户端调用 post api 时出现 CORS 错误
- azure - 按日期划分的 Azure Blob 复制分区
- google-apps-script - 如何将我的谷歌日历事件的 ID 转换为正确的格式,以便日历 API 在我的脚本中读取?
- neo4j - Did I just increase the db hit count (x2) by adding a node label into my cypher query?
- php - Laravel:防止 API 资源在模型更新后被修改
- minio - 如何在没有 accessKey 和 secretKey 的情况下开始使用 Minio?
- java - 如何找到多维数组的总平均值(java)
- kotlin - 在 Kotlin 中测试协程