问题
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