Home > Enterprise >  How many reads does using .contains() produce? - Flutter/Firebase
How many reads does using .contains() produce? - Flutter/Firebase

Time:10-18

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?

CodePudding user response:

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!

  • Related