Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Firestore sometimes not return anything, no error, nothing?

I'm doing a simple query and periodically Firestore doesn't return anything. No error, no results, nothing.

Firestore.firestore().collection("groupChats")
        .order(by: kUpdatedAt, descending: true)
        .whereField("memberIds", arrayContains: currentUserId)
        .limit(to: 15).getDocuments { [weak self] snapshot, error in 
             // nothing inside here ever hits
        }

I'm not really sure how to proceed or debug this since this seems to be inside of Firestore. The user has an internet connection. Pulling to refresh and calling that query again returns the same seeming no-op result.

Any ideas what's going on here? Thanks!

like image 840
Zack Shapiro Avatar asked Dec 10 '18 15:12

Zack Shapiro


People also ask

Can you have an empty collection in firestore?

In Firestore there's just no such thing as an "empty collection" and we have no mechanism today to "create" collections or "delete" collections other than by writing a document (to "create" the collection) and deleting all the documents (to "delete" the collection).

How do I retrieve my firestore data?

There are two ways to retrieve data stored in Cloud Firestore. Either of these methods can be used with documents, collections of documents, or the results of queries: Call a method to get the data. Set a listener to receive data-change events.

Is firestore real time?

Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing: 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.

What is firestore 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.


1 Answers

The issue ended up being caching is turned on by default and I had a massive cache on the device from development and migrations. Turning the offline caching off as part of the Firestore() initialization helped this significantly and made my app usable again.

like image 194
Zack Shapiro Avatar answered Oct 23 '22 00:10

Zack Shapiro