{"record":{"id":"e7e9574499880890","repo":"pubkey/rxdb","slug":"doc6","errorCode":"DOC6","errorMessage":"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","messagePattern":"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","errorType":"error_code","errorClass":"RxError","httpStatus":null,"severity":"error","filePath":"src/rx-document.ts","lineNumber":215,"sourceCode":"        );\n        /**\n         * Validate the schema path BEFORE looking at the document value\n         * so that invalid paths and non-ref fields surface as DOC5/DOC6\n         * errors even when the value at that path happens to be falsy.\n         * Previously the `!value` short-circuit below swallowed these errors.\n         */\n        if (!schemaObj) {\n            throw newRxError('DOC5', {\n                path\n            });\n        }\n        const ref = schemaObj.ref\n            ? schemaObj.ref\n            : (schemaObj.type === 'array' && schemaObj.items && (schemaObj.items as any).ref\n                ? (schemaObj.items as any).ref\n                : undefined);\n        if (!ref) {\n            throw newRxError('DOC6', {\n                path,\n                schemaObj\n            });\n        }\n\n        const refCollection: RxCollection = this.collection.database.collections[ref];\n        if (!refCollection) {\n            throw newRxError('DOC7', {\n                ref,\n                path,\n                schemaObj\n            });\n        }\n\n        const value = this.get(path);\n        if (!value) {\n            return PROMISE_RESOLVE_NULL;\n        }","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-document.ts#L197-L233","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nbestFriend: { type: 'string' } // DOC6 on populate\n// after\nbestFriend: { type: 'string', ref: 'heroes' }","handlingStrategy":"validation","validationCode":"function isRefField(doc: RxDocument, path: string): boolean {\n  const schemaObj = getSchemaByObjectPath(doc.collection.schema.jsonSchema, path) as any;\n  return !!schemaObj && (!!schemaObj.ref || schemaObj.type === 'array' && schemaObj.items?.ref);\n}\nif (!isRefField(doc, 'bestFriend')) return doc.get('bestFriend');","typeGuard":"function hasRef(schemaObj: any): schemaObj is { ref: string } {\n  return !!schemaObj && typeof schemaObj.ref === 'string';\n}","tryCatchPattern":"try {\n  return await doc.populate(path);\n} catch (err) {\n  if ((err as any).code === 'DOC6') return doc.get(path); // non-ref field\n  throw err;\n}","preventionTips":["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"],"tags":["schema","populate","ref"],"backgroundTag":"missing-ref-definition","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}