pubkey/rxdb · error · RxError
DOC6
DOC6
Error message
RxDB Error-Code: DOC6. 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
DOC6 is thrown by RxDocument.populate() when the field at the given path exists in the schema but is not a ref field, i.e. it has neither a 'ref' property nor array items with a 'ref'. populate() only makes sense on foreign-key fields; calling it on a plain string, number or object would have nothing to resolve. RxDB rejects this to make ref mistakes explicit.
Source
Thrown at src/rx-document.ts:215
);
/**
* 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', {
ref,
path,
schemaObj
});
}
const value = this.get(path);
if (!value) {
return PROMISE_RESOLVE_NULL;
}View on GitHub (pinned to af6fb65f94)
Solutions
- Add ref: '<collectionName>' to the field (or items) in the schema
- Call populate only on the foreign-key field, not on unrelated fields
- Use doc.get() instead of populate() if you only need the raw value
Example fix
// before
bestFriend: { type: 'string' } // DOC6 on populate
// after
bestFriend: { type: 'string', ref: 'heroes' } Defensive patterns
Strategy: validation
Validate before calling
function isRefField(doc: RxDocument, path: string): boolean {
const schemaObj = getSchemaByObjectPath(doc.collection.schema.jsonSchema, path) as any;
return !!schemaObj && (!!schemaObj.ref || schemaObj.type === 'array' && schemaObj.items?.ref);
}
if (!isRefField(doc, 'bestFriend')) return doc.get('bestFriend'); Type guard
function hasRef(schemaObj: any): schemaObj is { ref: string } {
return !!schemaObj && typeof schemaObj.ref === 'string';
} Try / catch
try {
return await doc.populate(path);
} catch (err) {
if ((err as any).code === 'DOC6') return doc.get(path); // non-ref field
throw err;
} Prevention
- Always declare ref (or items.ref) on foreign-key fields
- Use a schema lint/test that checks every field ending in Id/Ids has a ref
- Distinguish raw reads (get) from ref resolution (populate) in code review
- Enable dev-mode plugin to surface the exact schemaObj in the message
When it happens
Trigger: await doc.populate('name') where 'name' is a plain string field with no ref; populate on an array of strings whose items lack a ref; forgetting to add ref: 'otherCollection' to the field definition; using populate on an embedded object instead of a foreign key.
Common situations: Schema defined the field but omitted the ref attribute; developer assumed populate works on any field; array refs declared as { type: 'array', items: { type: 'string' } } without items.ref.
Related errors
AI-assisted analysis of pubkey/rxdb@af6fb65f94 (2026-08-31).
Data as JSON: /api/errors/e7e9574499880890.
Report an issue: GitHub.