My experience with Firestore

Sajad Asadi
Aratta Studios
Published in
3 min readOct 29, 2019

I have decided to use Firestore as a database and also a replacement for back-end in one of my apps.

Now, after a deep dive into it and facing some challenges, I want to share my experience with you.

First, I must say I have been using flutter as my mobile app development framework which has official plugins by flutter team for using firebase products.

In the beginning, it was so fun to use Firestore I even built some little apps for learning how to use Firestore, it was so easy and fun with simple CRUD operations and also making a live stream for something like chat apps.

But when I decided to use it in my app, I faced some problems.

Queries based on geo point ( Location )

I had to query my data based on geo point ( location ) and it was no way to run such a query in Firestore and after searching google I found a workaround, I have used Geohash to be able to query data for a certain distance. but I had more issues with this query.

Ranged queries on more than one field

Now I wanted to run a query something like

data with maximum distance N & minimum distance M & with birth date greater than X & with birth date lesser than Y

So simply I didn’t succeed to run such a query It even mentioned in Firestore documents that if I want to run a complex query like this, I must choose one of the conditions to use in a query then I must filter result data based on other conditions in my app. This is not a wise solution If there is a possibility of a large number of results.

Sort data based on a calculation

With two above problems, I still managed to do something inside of my app something like a lazy load.
But in the next step, I wanted to sort my data based on location, something like this:

data with maximum distance N & minimum distance M & with birth date greater than X & with birth date lesser than Y & order by ( A calculation with distance resulted by my location and target data location ) & limit 100 nearby data

I didn’t succeed at all because of the order by function just receives a field name and an optional ‘desc’ flag.

Maybe it was possible to get all data and then order them inside my app then filter a few of them but It’s not a solution if we have millions of data … besides even if I use cloud functions to do it costs performance to do a for loop in millions of data then sort them based on a calculation.

Which is possible in other DBs like mongo or MySQL just by the query itself.

Forced order by

If we use a range query on a field and then we decide to order it by another field, Firestore forces us to first order based on the field that we used range query on it then we can sort it by other fields.

Conclusion

In my experience for complex queries, I had to do most of the data filtration and sorting logic in the client-side which costs ram and CPU. Also, if data size exceeds a limit, it causes a freeze and crash.

So if you want to make a prototype or a simple app with no complex queries and data, I suggest Firestore but if your app is more than a simple CRUD function, it’s better to think carefully about using Firestore as DB or back-end …
In the end, I have decided to switch my DB to another cloud-based service or even buying a Cloud server and deploy a DBMS on it something like MySQL or Mongo.

--

--