如何获取Firestore中离线的记录 [英] How to get the records which are offline in Firestore

查看:67
本文介绍了如何获取Firestore中离线的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要下线,并使用以下代码在 city 集合中添加1个条目:

I want to go offline and add 1 entry in cities collection using this code below:

 firebase.firestore().collection("cities").doc("NY").set({
   name: "Los Angeles",
   state: "CA",
   country: "USA"
  capital: false
 })
 .then(function() {
    console.log("Document successfully written!");
 })
 .catch(function(error) {
    console.error("Error writing document: ", error);
 });

如何在上面添加以上代码

How do I add the above code inside

firebase.firestore().disableNetwork().then(function(){ .onSnapshot({includeMetadataChanges:true},(docSnapshot)=> {console.log(docSnapshot);});

以便我可以阅读所有来自 city 集合的文档,因为我必须在它们前面显示图标.

so that I can read all docs are offline from collection cities as I have to show icon in front of them.

推荐答案

Firestore不提供仅返回写入本地缓存但尚未同步的文档的查询.

Firestore doesn't offer a type of query that returns only documents written to local cache but have not been synchronized.

您能做的最好的事情就是正常地进行查询,并检查 DocumentSnapshot 对象的noreferrer>元数据. SnapshotMetadata 会告诉您文档具有尚未与服务器同步的未完成写入.

The best you can do is make the query normally, and inspect the metadata of each DocumentSnapshot object. The SnapshotMetadata will tell you if the document hasPendingWrites that are not yet synchronized with the server.

这篇关于如何获取Firestore中离线的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆