Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How many reads does using .contains() produce? – Flutter/Firebase

I’m using Firebase & Flutter and wondering how many reads does using .contains() produce?

For example: Let’s say we have a button that you can click on and whenever the current user clicks on it, it takes their UID and stores it in an array/list in the Firestore Database.

Then I want to check if the current user’s UID is inside of that list. To do this, I’m using .contains(uid). So as an example, let’s say the list contains a total of 10 different values/UIDs. Does that mean using .contains() would produce 10 reads or only 1?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Firestore read count based only on the entire document. Also you are fetching the doc and do .contains() in the client side. So this results in only 1 read.

By the way, you can add in an array without reading the doc. It adds to the array only if it does not have the item.

FirebaseFirestore.instance
        .collection('<collection name>')
        .doc('<docId>').update({'<arrayFieldKey>':FieldValue.arrayUnion([<new item>])});

Hope it helps!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading