Reputation: 71
I'm facing an issue while using .set() function in offline mode for creating a document in firestore. But .update() , .get() and .delete() functions are working in offline mode.
below is the code snippet
firebase.firestore().collection(this.state.mainCollectionId)
.doc(this.state.authKey)
.collection(collectionId.toString())
.doc(docId)
.get()
.then(docData => {
if (docData.exists) {
// console.log("daily Activity exists");
} else {
firebase.firestore().collection(this.state.mainCollectionId)
.doc(this.state.authKey)
.collection(collectionId.toString())
.doc(docId)
.set({
id:1234,
collectionId: collectionId.toString(),
authKey: this.state.userDatails.authKey,
name: this.state.userDatails.name,
email: this.state.userDatails.email
}).then(data =>{});
}
});
and error that I'm getting:
> Error: Firestore: The service is currently unavailable. (firestore/unavailable).
at createErrorFromErrorData (NativeModules.js:146)
at NativeModules.js:95
at MessageQueue.__invokeCallback (MessageQueue.js:392)
at MessageQueue.js:128
at MessageQueue.__guard (MessageQueue.js:291)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:127)
at debuggerWorker.js:72
Upvotes: 5
Views: 663
Reputation: 71
I got to know the answer for this question. there is a if condition If(docData.exists) need to remove this code because firebase uses the cache in device. The if condition will look for the document that is not there in the cache.
Upvotes: 2