Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore's hasPendingWrites() returns false on deleted document

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;
    }
}
like image 439
TruffelNL Avatar asked Feb 26 '19 11:02

TruffelNL


People also ask

How do I use onSnapshot?

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.

Is cloud firestore real time?

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.

How do you listen for document changes in cloud firestore using flutter?

listen((querySnapshot) { querySnapshot. documentChanges. forEach((change) { // Do something with change }); });

How do I connect node JS to firestore database?

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.


1 Answers

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.

like image 176
TruffelNL Avatar answered Nov 14 '22 23:11

TruffelNL