pubkey/rxdb · error · RxError
DOC4
DOC4
Error message
RxDB Error-Code: DOC4. 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
DOC4 is thrown by RxDocument.get$()/get() when the given object path is not defined in the collection's RxSchema. RxDB validates the path against the JSON schema before creating an observable, so a typo or a path outside the schema fails fast instead of emitting undefined. It guards against silently observing a field that can never exist.
Source
Thrown at src/rx-document.ts:161
if (path === this.primaryPath) {
throw newRxError('DOC2');
}
// final fields cannot be modified and so also not observed
if (this.collection.schema.finalFields.includes(path)) {
throw newRxError('DOC3', {
path
});
}
const schemaObj = getSchemaByObjectPath(
this.collection.schema.jsonSchema,
path
);
if (!schemaObj) {
throw newRxError('DOC4', {
path
});
}
}
return this.$
.pipe(
map((data: any) => getProperty(data, path)),
distinctUntilChanged((prev: any, curr: any) => {
/**
* Use deepEqual for non-primitive values (objects/arrays)
* because the default === comparison always fails across
* document revisions since each revision creates new object references.
*/
return deepEqual(prev, curr);
})
);
},View on GitHub (pinned to af6fb65f94)
Solutions
- Fix the path string so it matches a path defined in the collection's JSON schema
- Verify with collection.schema.jsonSchema (or getSchemaByObjectPath) that the path exists
- Enable the dev-mode plugin during development to get the full message including the offending path
Example fix
// before
doc.get$('nam.last'); // DOC4: path not in schema
// after
doc.get$('name.last'); // path exists in the schema Defensive patterns
Strategy: validation
Validate before calling
import { getSchemaByObjectPath } from 'rxdb/plugins/schema-helper';
function pathExists(doc: RxDocument, path: string): boolean {
return !!getSchemaByObjectPath(doc.collection.schema.jsonSchema, path);
}
if (!pathExists(doc, 'name.last')) throw new Error('unknown schema path'); Type guard
function hasSchemaPath(doc: RxDocument, path: string): path is string {
return !!getSchemaByObjectPath(doc.collection.schema.jsonSchema, path);
} Try / catch
try {
doc.get$(path).subscribe(render);
} catch (err) {
if ((err as any).code === 'DOC4') console.warn('bad path', path);
} Prevention
- Derive paths from constants or the schema itself instead of string literals
- Run with the dev-mode plugin in development to get full messages
- Add tests that assert schema paths used by UI code exist
- Review schema migrations for renamed fields and update all path usages
When it happens
Trigger: Calling doc.get$('name.lastname') or doc.get('field.x') where 'name.lastname' (or any intermediate segment) is not declared in the collection schema; using dot-notation paths that reference nested properties not present in the JSON schema; observing a removed or renamed field after a schema change.
Common situations: Field renamed in schema but queries/observables still use the old name; assuming nested paths are allowed without declaring nested objects in the schema; forgetting to update secondary indexes or UI bindings after a schema migration.
Related errors
AI-assisted analysis of pubkey/rxdb@af6fb65f94 (2026-08-31).
Data as JSON: /api/errors/48f67eae150a625c.
Report an issue: GitHub.