How do i get the records which are offline - Firestore

南楼画角 提交于 2020-03-25 18:18:11

问题


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() { and .onSnapshot({includeMetadataChanges: true}, (docSnapshot) => { console.log(docSnapshot); });

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

Please guide.


回答1:


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

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.



来源:https://stackoverflow.com/questions/60834041/how-do-i-get-the-records-which-are-offline-firestore

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