pubkey/rxdb · error · RxError

DOC5

DOC5

Error message

RxDB Error-Code: DOC5. 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

DOC5 is thrown by RxDocument.populate() when the given path does not exist in the collection schema. Before reading the document value, RxDB validates that the path is a real schema path; a nonexistent path is a programming error, not an empty result. The validation was moved before the falsy-value check so invalid paths surface even when the stored value is falsy.

Source

Thrown at src/rx-document.ts:205

        );
    },

    /**
     * populate the given path
     */
    populate(this: RxDocument, path: string): Promise<RxDocument | null> {
        const schemaObj = getSchemaByObjectPath(
            this.collection.schema.jsonSchema,
            path
        );
        /**
         * Validate the schema path BEFORE looking at the document value
         * so that invalid paths and non-ref fields surface as DOC5/DOC6
         * errors even when the value at that path happens to be falsy.
         * Previously the `!value` short-circuit below swallowed these errors.
         */
        if (!schemaObj) {
            throw newRxError('DOC5', {
                path
            });
        }
        const ref = schemaObj.ref
            ? schemaObj.ref
            : (schemaObj.type === 'array' && schemaObj.items && (schemaObj.items as any).ref
                ? (schemaObj.items as any).ref
                : undefined);
        if (!ref) {
            throw newRxError('DOC6', {
                path,
                schemaObj
            });
        }

        const refCollection: RxCollection = this.collection.database.collections[ref];
        if (!refCollection) {
            throw newRxError('DOC7', {

View on GitHub (pinned to af6fb65f94)

Solutions

  1. Correct the path so it matches a schema field (the one holding the ref)
  2. Check the schema definition declares the field, e.g. { type: 'string', ref: 'heroes' }
  3. Run populate only on fields confirmed via collection.schema.jsonSchema

Example fix

// before
await doc.populate('friend'); // DOC5: no such schema path
// after
await doc.populate('bestFriend'); // field exists in schema
Defensive patterns

Strategy: validation

Validate before calling

import { getSchemaByObjectPath } from 'rxdb/plugins/schema-helper';
function canPopulate(doc: RxDocument, path: string): boolean {
  return !!getSchemaByObjectPath(doc.collection.schema.jsonSchema, path);
}
if (canPopulate(doc, 'bestFriend')) await doc.populate('bestFriend');

Type guard

function isSchemaPath(doc: RxDocument, path: string): boolean {
  return !!getSchemaByObjectPath(doc.collection.schema.jsonSchema, path);
}

Try / catch

try {
  const referenced = await doc.populate(path);
} catch (err) {
  if (['DOC5', 'DOC6'].includes((err as any).code)) {
    // fall back to raw value
    return doc.get(path);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling await doc.populate('friendId') where 'friendId' is not a path in the schema; a typo in the path; calling populate on a field that was removed or renamed in the schema; populate on an intermediate path that does not resolve via getSchemaByObjectPath.

Common situations: Renaming a foreign-key field without updating populate calls; confusing the ref field name with the referenced collection name; copy-pasting populate paths between collections with different schemas.

Related errors


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