pubkey/rxdb · error · RxError

QU14

QU14

Error message

RxDB Error-Code: QU14. Hint: Error messages are not included in RxDB core to reduce build size. To show the full error messages and to ensure that you do not make any mistakes when using RxDB, use the dev-mode plugin when you are in development mode: https://rxdb.info/dev-mode.html?console=error

What it means

QU14 is thrown when a count() query is executed and the storage reports the count mode as 'slow' while database.allowSlowCount is false. RxDB refuses slow counts (full index scans) by default because counting without a suitable index can degrade performance badly.

Source

Thrown at src/rx-query.ts:324

                    mustBeQueried.push(id);
                }
            }
            // everything which was not in docCache must be fetched from the storage
            if (mustBeQueried.length > 0) {
                const docs = await this.collection.storageInstance.findDocumentsById(mustBeQueried, false);
                for (let i = 0; i < docs.length; i++) {
                    docsData.push(docs[i]);
                }
            }
            result = {
                result: docsData,
                counter: this.collection._changeEventBuffer.getCounter()
            };
        } else if (this.op === 'count') {
            const preparedQuery = this.getPreparedQuery();
            const countResult = await this.collection.storageInstance.count(preparedQuery);
            if (countResult.mode === 'slow' && !this.collection.database.allowSlowCount) {
                throw newRxError('QU14', {
                    collection: this.collection,
                    queryObj: this.mangoQuery
                });
            } else {
                result = {
                    result: countResult.count,
                    counter: this.collection._changeEventBuffer.getCounter()
                };
            }
        } else {
            const queryResult = await queryCollection<RxDocType>(this as any);
            result = {
                result: queryResult.docs,
                counter: queryResult.counter
            };
        }

        /**

View on GitHub (pinned to af6fb65f94)

Solutions

  1. Set allowSlowCount: true in createRxDatabase options if the slow count is acceptable for your use case.
  2. Restructure the count selector so it can run on an index (count selectors only support $and-combined primitive operators); verify with the query plan that mode is no longer 'slow'.
  3. Maintain a counter document updated via hooks/increments instead of counting queries at runtime.
  4. Fetch the matching documents and count client-side if the dataset is small and bounded.

Example fix

// before
const db = await createRxDatabase({ name: 'mydb', storage: getRxStorageDexie() });
const n = await myCollection.count({ selector: { age: { $gt: 18 } } }).exec(); // QU14

// after
const db = await createRxDatabase({
  name: 'mydb',
  storage: getRxStorageDexie(),
  allowSlowCount: true
});
const n = await myCollection.count({ selector: { age: { $gt: 18 } } }).exec();
Defensive patterns

Strategy: try-catch

Validate before calling

if (!db.allowSlowCount) {
  console.warn('count queries without a fitting index will throw QU14');
}
const n = await collection.count(selector).exec();

Type guard

function canCount(db: { allowSlowCount?: boolean }): boolean {
  return db.allowSlowCount === true;
}

Try / catch

try {
  const n = await collection.count(selector).exec();
} catch (err) {
  if (err?.code === 'QU14') {
    // slow count refused: fall back to a counter document or enable allowSlowCount
    return await getCounterFallback(selector);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling collection.count(selector).exec() where the storage instance cannot serve the count from an index and returns mode 'slow', and the database was created without allowSlowCount: true.

Common situations: Counting on a non-indexed or partially selective selector; new RxDB versions (10+) enforcing the slow-count guard while the app previously counted freely; migrating code that used .find().exec().length instead of the count API.

Related errors


AI-assisted analysis of pubkey/rxdb@af6fb65f94 (2026-08-31). Data as JSON: /api/errors/694a6488893f9817. Report an issue: GitHub.