{"record":{"id":"cec65b497a5fd9ce","repo":"pubkey/rxdb","slug":"doc2","errorCode":"DOC2","errorMessage":"RxDB Error-Code: DOC2. 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: DOC2\\. 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":145,"sourceCode":"            _this.$,\n            _this.getLatest()._data,\n            _this.collection.database\n        );\n    },\n\n    /**\n     * returns observable of the value of the given path\n     */\n    get$(this: RxDocument, path: string): Observable<any> {\n        if (overwritable.isDevMode()) {\n            if (path.includes('.item.')) {\n                throw newRxError('DOC1', {\n                    path\n                });\n            }\n\n            if (path === this.primaryPath) {\n                throw newRxError('DOC2');\n            }\n\n            // final fields cannot be modified and so also not observed\n            if (this.collection.schema.finalFields.includes(path)) {\n                throw newRxError('DOC3', {\n                    path\n                });\n            }\n\n            const schemaObj = getSchemaByObjectPath(\n                this.collection.schema.jsonSchema,\n                path\n            );\n\n            if (!schemaObj) {\n                throw newRxError('DOC4', {\n                    path\n                });","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-document.ts#L127-L163","documentation":"DOC2 is thrown when you try to observe the primary key field of a document via RxDocument.get$(path), e.g. get$('id'). The primary key never changes for a document, so observing it is pointless; read it directly with doc.primary or doc.get('id')... actually read it statically. This check only runs in dev mode.","triggerScenarios":"Calling doc.get$(this.collection.schema.primaryPath), e.g. doc.get$('id'), in dev mode; passing a dynamically chosen path that happens to equal the primary path.","commonSituations":"Building generic field-observation helpers that iterate schema fields including the primary key; misunderstanding that the primary field needs reactivity; generating paths from a schema key list.","solutions":["Read the primary key directly: const id = doc.primary; no observable needed.","Filter the primary path out of any generated field list before calling get$.","If you need a reactive value that equals the primary key, use doc.$ or an observable of the document itself and map to doc.primary."],"exampleFix":"// before\ndoc.get$('id').subscribe(id => ...);\n// after\nimport { map } from 'rxjs';\ndoc.$.pipe(map(d => d.primary)).subscribe(id => ...);\n// or simply: const id = doc.primary;","handlingStrategy":"validation","validationCode":"function assertNotPrimary(doc, path) {\n  if (path === doc.collection.schema.primaryPath) {\n    throw new Error('Primary key does not change, read it statically: doc.primary');\n  }\n}","typeGuard":"function isNonPrimaryKey(doc, path) {\n  return path !== doc.collection.schema.primaryPath;\n}","tryCatchPattern":"try {\n  obs = doc.get$(path);\n} catch (err) {\n  if (String(err?.code) === 'DOC2') {\n    // primary key never changes: emit it once from the static value\n    import('rxjs').then(({ of }) => obs = of(doc.primary));\n  } else {\n    throw err;\n  }\n}","preventionTips":["Read the primary key with doc.primary instead of get$.","Exclude schema.primaryPath when iterating schema fields for reactive bindings.","Remember the primary value is immutable per document, so it never needs observation.","Keep the dev-mode plugin enabled while developing to catch this early."],"tags":["rxdocument","observable","primary-key","dev-mode"],"backgroundTag":"unsupported-observable-path","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}