【问题标题】:Firestore cache not syncFirestore 缓存不同步
【发布时间】:2021-01-11 17:08:37
【问题描述】:

我在 typescript 上使用 firestore,启用了缓存 (enablePersistence)

问题是当我在 firestore 中删除某些产品时,当我从 firestore 获取时(通过管理界面,或通过应用程序的其他实例),似乎是产品从缓存中返回(然后删除不与缓存同步)

async getProductList(): Promise<Product[]> {
        const collection = this.db.collection(`products`)
        const snapshot = await collection.get();

        return snapshot.docs.map((doc: any) => {
            console.log(doc.data())
            return doc.data()
        });
}

查看firestore模拟器(只有1个产品,我删除了id为5656的产品)

但在我的应用程序控制台中,我得到了 2 个产品(已删除一个):

【问题讨论】:

    标签: javascript typescript firebase google-cloud-firestore


    【解决方案1】:

    我使用的是 Firestore 模拟器

       firebase.firestore().settings({
            host: "localhost:8080",
            ssl: false,
            experimentalForceLongPolling: true 
        });
    

    这就是问题所在。当我使用真正的 Firestore 环境时,我不再有问题了。奇怪!

    【讨论】:

      猜你喜欢
      • 2018-04-22
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 2014-02-12
      • 1970-01-01
      相关资源
      最近更新 更多