Skip to content

Firestore error

Firestore: in query has more than 30 values

Firestore in and array-contains-any queries allow up to 30 comparison values, and not-in allows 10. A longer list throws an invalid query error. The limit is fixed, so split the list into chunks of 30 and merge the results in the app.

Rather hand it over? App Fix Ticket: One reproducible bug in an existing mobile or web app, diagnosed and fixed.The Fix is $1,200 in total. The $450 Diagnosis is optional and credited toward it.

Full refund if Simon can’t take it on once he sees your project, or if you cancel before work starts. Refund terms.

Short answer

Split the ids into groups of 30, run one query per group in parallel, and merge the results. Combining two in filters, or in with or, multiplies the count, so keep the total under 30. For long lists, store a field you can query with one equality filter instead.

Rather not fix it yourself? App Fix Ticket fixes one reproducible bug at a fixed price, with an optional Diagnosis that is credited toward the fix.

Why the query fails, and the fix

  1. 01

    The list has more than 30 values

    “Use the in operator to combine up to 30 equality (==) clauses on the same field with a logical OR.” Firebase, Simple and compound queries (in)

    An in filter on a list of ids, such as the people a user follows, works until the list passes 30. Split it and query each part.

    // Web SDK
    import { collection, query, where, getDocs, documentId } from 'firebase/firestore';
    
    const unique = [...new Set(ids)];
    const chunks = [];
    for (let i = 0; i < unique.length; i += 30) chunks.push(unique.slice(i, i + 30));
    const snaps = await Promise.all(
      chunks.map((c) => getDocs(query(collection(db, 'users'), where(documentId(), 'in', c)))),
    );
    const users = snaps.flatMap((s) => s.docs.map((d) => ({ id: d.id, ...d.data() })));
  2. 02

    Two filters multiply the count

    “These queries are limited to 30 disjunctions based on the query's disjunctive normal form. This limit is fixed and cannot be adjusted.” Firebase, Simple and compound queries (Limitations)

    Firestore counts the or, in and array-contains-any parts together. Two in filters with 6 values each make 36 combinations, which is over the limit even though each list is short. If the query has another in or or, divide 30 by that part’s size to get the chunk size.

  3. 03

    not-in has a lower limit

    “not-in supports up to 10 comparison values.” Firebase, Simple and compound queries (Limitations)

    not-in allows only 10 values. To hide more, filter them out in the app after the query, or store a flag on the documents and filter on that.

  4. 04

    The query shape doesn’t fit the data

    If a screen always needs hundreds of ids, change the data instead: store the owner or group id on each document and query it with one == filter, or keep a list on a single document. On a server, the Admin SDK getAll() reads many known documents in one call. Chunked reads still cost one read per document.

Checked against the vendor’s docs on : Firebase docs: Simple and compound queries.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

“Very responsive, attentive to fixing bugs, and completed the project as needed! Thank you!”
A buyer in the United States, July 2022. Shopify on Fiverr
Read 126 of the 127 Fiverr reviews

Related: Firestore query requires an index · Firestore quota exceeded · Firestore invalid document reference · FCM payload size limit exceeded

Questions

More on this error

Can the 30 limit be raised?

No. Firebase says the limit is fixed. Split the list or change how the data is stored.

Do chunked queries keep the order?

Not across chunks. Each query returns its own results, so sort the merged list in the app.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it. If you already know the cause, you can pay for the fix directly; if not, start with a written diagnosis, which is credited toward the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Ask Simon for a price range

Send the error and what you were doing. Simon replies by email, usually within one business day, with a price range.