{"record":{"id":"cfa411ba3c0851ba","repo":"pubkey/rxdb","slug":"doc7","errorCode":"DOC7","errorMessage":"RxDB Error-Code: DOC7. 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: DOC7\\. 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":223,"sourceCode":"            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        }\n\n        if (schemaObj.type === 'array') {\n            return refCollection.findByIds(value).exec().then(res => {\n                // Preserve the original array order of the ref ids\n                // instead of using the Map iteration order which depends\n                // on the query cache and storage return order.\n                const result = [];\n                for (let i = 0; i < value.length; i++) {","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-document.ts#L205-L241","documentation":"DOC7 is thrown by RxDocument.populate() when the schema field has a ref, but no collection with that name exists in the database (this.collection.database.collections[ref] is undefined). The ref points to a collection that was never added via addCollections, or was added under a different name. RxDB cannot resolve the reference without the target collection.","triggerScenarios":"await doc.populate('bestFriend') where the schema says ref: 'heroes' but the database has no collection named 'heroes'; collection added as 'hero' (typo/singular vs plural); ref collection only created conditionally at runtime; ref copied from another database setup.","commonSituations":"addCollections call missing the referenced collection; case-sensitive name mismatch between schema ref and collection name; multi-database setups where the ref exists in one database instance but not the one in use.","solutions":["Add the referenced collection to the database via addCollections with the exact name used in ref","Align the schema ref string with the actual collection name (names are case-sensitive)","Ensure the collection is created before any populate() call runs"],"exampleFix":"// before\n// schema: { ref: 'heroes' } but db only has 'hero'\nawait doc.populate('bestFriend'); // DOC7\n// after\nawait myDatabase.addCollections({ heroes: { schema: heroSchema } });","handlingStrategy":"validation","validationCode":"function refCollectionExists(doc: RxDocument, path: string): boolean {\n  const schemaObj = getSchemaByObjectPath(doc.collection.schema.jsonSchema, path) as any;\n  const ref = schemaObj?.ref ?? schemaObj?.items?.ref;\n  return !!ref && !!doc.collection.database.collections[ref];\n}\nif (!refCollectionExists(doc, 'bestFriend')) throw new Error('missing ref collection');","typeGuard":"function collectionExists(db: RxDatabase, name: string): boolean {\n  return Object.prototype.hasOwnProperty.call(db.collections, name);\n}","tryCatchPattern":"try {\n  return await doc.populate(path);\n} catch (err) {\n  if ((err as any).code === 'DOC7') {\n    await db.addCollections({ [expectedRef]: { schema } }); // repair and retry once\n    return await doc.populate(path);\n  }\n  throw err;\n}","preventionTips":["Create all collections in one setup function before app start","Add a startup assertion that every schema ref resolves to an existing collection","Keep collection names in shared constants to avoid case/typo mismatches","Check database.collections keys when wiring multi-database setups"],"tags":["populate","collection-lookup","ref"],"backgroundTag":"collection-not-found","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}