{"record":{"id":"fab64513eb3f9ea0","repo":"pubkey/rxdb","slug":"doc18","errorCode":"DOC18","errorMessage":"\n        RxDB Error-Code: ${message}.\n        Hint: Error messages are not included in RxDB core to reduce build size.\n        To show the full error messages and to ensure that you do not make any mistakes when using RxDB,\n        use the dev-mode plugin when you are in development mode: https://rxdb.info/dev-mode.html?console=error\n        \nFind out more about this error here: https://rxdb.info/errors.html?console=errors#DOC18 \nStill stuck? Ask in the RxDB Discord: https://rxdb.info/chat \n","messagePattern":"\n        RxDB Error-Code: \\$\\{message\\}\\.\n        Hint: Error messages are not included in RxDB core to reduce build size\\.\n        To show the full error messages and to ensure that you do not make any mistakes when using RxDB,\n        use the dev-mode plugin when you are in development mode: https://rxdb\\.info/dev-mode\\.html\\?console=error\n        \nFind out more about this error here: https://rxdb\\.info/errors\\.html\\?console=errors#DOC18 \nStill stuck\\? Ask in the RxDB Discord: https://rxdb\\.info/chat \n","errorType":"error_code","errorClass":"RxError","httpStatus":null,"severity":"error","filePath":"src/rx-schema-helper.ts","lineNumber":159,"sourceCode":"    return ensureNotFalsy(schemaPart.maxLength);\n}\n\n/**\n * Returns the composed primaryKey of a document by its data.\n */\nexport function getComposedPrimaryKeyOfDocumentData<RxDocType>(\n    jsonSchema: RxJsonSchema<RxDocType> | RxJsonSchema<RxDocumentData<RxDocType>>,\n    documentData: Partial<RxDocType>\n): string {\n    if (typeof jsonSchema.primaryKey === 'string') {\n        return (documentData as any)[jsonSchema.primaryKey];\n    }\n\n    const compositePrimary: CompositePrimaryKey<RxDocType> = jsonSchema.primaryKey as any;\n    return compositePrimary.fields.map(field => {\n        const value = getProperty(documentData as any, field as string);\n        if (typeof value === 'undefined') {\n            throw newRxError('DOC18', { args: { field, documentData } });\n        }\n        return value;\n    }).join(compositePrimary.separator);\n}\n\n\n/**\n * Normalize the RxJsonSchema.\n * We need this to ensure everything is set up properly\n * and we have the same hash on schemas that represent the same value but\n * have different json.\n *\n * - Orders the schemas attributes by alphabetical order\n * - Adds the primaryKey to all indexes that do not contain the primaryKey\n * - We need this for deterministic sort order on all queries, which is required for event-reduce to work.\n *\n * @return RxJsonSchema - ordered and filled\n */","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-schema-helper.ts#L141-L177","documentation":"DOC18 is thrown by getComposedPrimaryKeyOfDocumentData() when one of the fields that make up the composite primary key is undefined in the document data. RxDB cannot compute the document id because a required key component is missing. It is raised whenever any code needs to derive the primary key: checkpoints, internal documents, meta rows, insert helpers.","triggerScenarios":"Inserting/upserting a document where a primaryKey.fields entry is undefined or absent, e.g. schema primaryKey fields ['firstName','lastName'] and insert({firstName:'bar'}) without lastName. Also triggered indirectly via useId, checkpoint writes, replication meta rows (getMetaWriteRow) or getPrimaryKeyOfInternalDocument when the input data lacks a key field.","commonSituations":"Partial updates or patch objects passed where full document data is expected; documents from an older schema version missing a newly added key field; replication upstream data that does not contain all key fields; typos in field names (JS silently yields undefined).","solutions":["Ensure every field listed in schema.primaryKey.fields is present in the document before insert/upsert.","Use the dev-mode plugin to see the exact missing field and documentData in the error args.","Check for typos in field names and that nested fields (dot-separated in primaryKey.fields) actually exist on the object.","If documents come from an old version, run a migration strategy that fills the new key field before writes."],"exampleFix":"// before\nawait collection.insert({ firstName: 'bar' }); // lastName missing\n// after\nawait collection.insert({ firstName: 'bar', lastName: 'baz' });","handlingStrategy":"validation","validationCode":"import { getPrimaryKeyOfInternalDocument } from 'rxdb/plugins/rx-schema-helper';\nfunction hasAllKeyFields(schema: RxJsonSchema<any>, data: Record<string, any>): boolean {\n  const { fields } = schema.primaryKey as any;\n  return fields.every((f: string) => getProperty(data, f) !== undefined);\n}","typeGuard":"function isInsertable<T>(schema: RxJsonSchema<T>, data: Partial<T>): data is T {\n  const composite = schema.primaryKey as CompositePrimaryKey<T>;\n  return composite.fields.every(field => getProperty(data as any, field as string) !== undefined);\n}","tryCatchPattern":"try {\n  await collection.insert(data);\n} catch (err: any) {\n  if (err.code === 'DOC18') {\n    const missing = err.parameters?.args?.field;\n    throw new Error(`Primary key field '${missing}' missing on document`);\n  } else throw err;\n}","preventionTips":["Before insert/upsert, assert every primaryKey.fields entry exists on the object.","Type your documents so key fields are non-optional in TypeScript.","When adding a key field in a schema migration, backfill it in the migration strategy.","Watch for typos: undefined key fields fail silently until this error fires."],"tags":["schema","primary-key","composite-key","validation"],"backgroundTag":"missing-primary-key-field","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}