> For the complete documentation index, see [llms.txt](https://estare.gitbook.io/firebase-auth-firestore-and-storage-plugin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://estare.gitbook.io/firebase-auth-firestore-and-storage-plugin/plugin-back-end-actions/firestore-backend/count-a-list-of-documents.md).

# Count a list of documents

This action performs an aggregation operation on a Firestore collection, counting the number of document according to the provided query filters.

***

## <mark style="color:blue;">Inputs and Settings</mark>

<div align="left"><figure><img src="https://284736847-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiWu3FezEjWxrPbkf8zIP%2Fuploads%2Fwhrc1eafki2VohK3kMSc%2Fimage.png?alt=media&amp;token=13d9cc7b-f7dd-4f4b-af54-26bb2702616f" alt=""><figcaption></figcaption></figure></div>

### Collection

The name or ID of the collection you want to count document from.

### Query filters

This options allow you to choose fields from which to filter your query.

#### Available query operators

You can read more on the [Cloud Firestore documentation](https://firebase.google.com/docs/firestore/query-data/queries#query_operators).

<div align="left"><figure><img src="https://284736847-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiWu3FezEjWxrPbkf8zIP%2Fuploads%2FZzduHWvShdP2FWiBBVEB%2Fimage.png?alt=media&amp;token=3a6b00e0-85b3-4281-82a9-f9e9022dc45c" alt=""><figcaption><p>Query filter operators</p></figcaption></figure></div>

<table><thead><tr><th width="222">Operator</th><th>Description</th></tr></thead><tbody><tr><td>&#x3C;</td><td>Gets values less than the provided input (must be of type number or date)</td></tr><tr><td>&#x3C;=</td><td>Gets values less than or equal to the provided input (must be of type number or date)</td></tr><tr><td>==</td><td>Gets values equal to the provided input.</td></tr><tr><td>></td><td>Gets values greater than the provided input (must be of type number or date).</td></tr><tr><td>>=</td><td>Gets values greater than or equal to the provided input (must be of type number or date).</td></tr><tr><td>array-contains</td><td>Gets values where the field of type array/list has the value provided as input.</td></tr><tr><td>array-contains-any</td><td>Gets values where the field of type array/list any of the array of values provided as input.</td></tr><tr><td>in</td><td>Gets values where the field value is present on the array of values provided as input.</td></tr><tr><td>not-in</td><td>Gets values where the field value is not present on the array of values provided as input.</td></tr></tbody></table>

{% hint style="warning" %}
Firestore supports only one filter of type "array-contains", "array-contains-any", "in" or "not-in" per query. If you try to use more than one, the first one will be considered by the plugin, but the other's will be ignored.
{% endhint %}

{% hint style="warning" %}
Firestore does not offer "text" filters like the Bubble "contains keywords" option, because of the way they structure the database using indexes. For this kind os searches they recomend the use of external services like [Algolia](https://www.algolia.com/).
{% endhint %}

#### Types of filter values

Since Bubble is not flexible on the type of data we can define on plugins, the best way to implement our plugin was to work with texts. So each value you put on query values must be interpreted the right way to perform the Firestore Query. Defining a "query filter value type" can help us get it right.

So here are the types of query filter values:

<div align="left"><figure><img src="https://284736847-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiWu3FezEjWxrPbkf8zIP%2Fuploads%2FgSrSn4QTUtXVZvfe8i3f%2Fimage.png?alt=media&amp;token=a1396fe3-bcce-4c81-952d-3f72882056de" alt=""><figcaption><p>Query filter value types</p></figcaption></figure></div>

<table><thead><tr><th width="185">Type</th><th>How it will be handled</th></tr></thead><tbody><tr><td>auto</td><td>The plugin will try to infer the type from the input you provided.</td></tr><tr><td>text</td><td>Treated as a text value.</td></tr><tr><td>number</td><td>Treated as a number value.</td></tr><tr><td>boolean (true/false)</td><td>Treated as a true or false (yes/no) value.</td></tr><tr><td>date</td><td>Treated as a Date type. The plugin will convert the value to a Date.</td></tr><tr><td>array</td><td>Treated as a list in JavaScript format (e.g. ["item1", "item2", "item3"]).<br>If you need to use it on Bubble's lists, you can apply the ":format as text" message to the list, to build the array string into that format.</td></tr><tr><td>reference (coll/doc_id)</td><td>Treated as a document reference.<br>Document references are always handled by the plugin as paths to a document. For instance, if you want to get the reference for a document from the "tasks" collection with an id "1234", you should right "tasks/1234"</td></tr></tbody></table>

{% hint style="info" %}
Arrays and lists are always handled in JavaScript notation, which means each value should be comma separated and must be between brackets.

An array of number should be provided as a text like: \[1, 3, 45, 2]

An array of texts should contain balues between quotes: \["text1", "text2", "text3"]
{% endhint %}

{% hint style="info" %}
Document references are always handled by the plugin as paths to a document. For instance, if you want to get the reference for a document from the "tasks" collection with an id "1234", you should right "tasks/1234"
{% endhint %}

***

## <mark style="color:blue;">Returned Values</mark>

<div align="left"><figure><img src="https://284736847-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiWu3FezEjWxrPbkf8zIP%2Fuploads%2Fcxuon6BLkEBtJfeP3g2X%2Fimage.png?alt=media&amp;token=6fe57c26-b11c-45fb-a9f2-73251df91f54" alt=""><figcaption></figcaption></figure></div>

### Count

The resulting number, with the number of documents for the given query.

{% hint style="info" %}
On Firestore, on the count operation, each 1000 documents will account for 1 document read.
{% endhint %}
