I have a registered a listener which listens to changes to a query. When a document is removed/deleted, it needs to check if the change was local or not. If the change is local, a message is displayed. If it was not local, the object is just removed.
The problem is that hasPendingWrites()
returns false
when checked in the listener. Why is that? According to Firestore docs, it should be true
the first time as the listener is immediately triggered on alteration of the local cache.
Simplified code of AsyncArrayHandler, which is called when the listener is activated:
for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges())
{
changeIsMadeLocal = documentChange.getDocument().getMetadata().hasPendingWrites();
switch (documentChange.getType())
{
case REMOVED:
if (changeIsMadeLocal)
{
//do stuff here
}
break;
}
}
You can listen to a document with the onSnapshot() method. An initial call using the callback you provide creates a document snapshot immediately with the current contents of the single document. Then, each time the contents change, another call updates the document snapshot.
Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database. Realtime Database is Firebase's original database.
listen((querySnapshot) { querySnapshot. documentChanges. forEach((change) { // Do something with change }); });
Setting up the Node. First, you'll need to go to the Service Accounts menu in Google Cloud Platform account (it's under IAM & Admin). From there, generate a new private key, save it as a JSON file, and add it to your server. Then, in your index.
For everyone(and looking at the views, that's almost no one)running into the same problem as me, Firebase is looking into it and it seems it's a bug only present on certain devices and emulators. They are not quite sure where it's coming from but trying to find out.
When they give me more information, I'll edit this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With