{"record":{"id":"1d135050c135d09f","repo":"pubkey/rxdb","slug":"doc11","errorCode":"DOC11","errorMessage":"RxDB Error-Code: DOC11. 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: DOC11\\. 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":381,"sourceCode":"            return docData;\n        });\n    },\n\n    /**\n     * saves the new document-data\n     * and handles the events\n     */\n    async _saveData<RxDocType>(\n        this: RxDocument<RxDocType>,\n        newData: RxDocumentWriteData<RxDocType>,\n        oldData: RxDocumentData<RxDocType>\n    ): Promise<RxDocument<RxDocType>> {\n        isWriteAllowed(this.collection);\n        newData = flatClone(newData);\n\n        // deleted documents cannot be changed\n        if (this._data._deleted) {\n            throw newRxError('DOC11', {\n                id: this.primary,\n                document: this\n            });\n        }\n        await beforeDocumentUpdateWrite(this.collection, newData, oldData);\n        const writeRows = [{\n            previous: oldData,\n            document: newData\n        }];\n        const writeResult = await this.collection.storageInstance.bulkWrite(writeRows, 'rx-document-save-data');\n\n        const isError = writeResult.error[0];\n        throwIfIsStorageWriteError(this.collection, this.primary, newData, isError);\n\n        await this.collection._runHooks('post', 'save', newData, this);\n        return this.collection._docCache.getCachedRxDocument(\n            getWrittenDocumentsFromBulkWriteResponse(\n                this.collection.schema.primaryPath,","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-document.ts#L363-L399","documentation":"DOC11 is thrown by _saveData when a write is attempted on a document whose internal _deleted flag is true. Deleted RxDocuments are immutable placeholders; they cannot be modified, patched, or saved again. The dev-mode plugin reveals the full message including the document id.","triggerScenarios":"Calling doc.modify(fn), doc.patch(...), or doc.save() on a document instance that was removed earlier (e.g. via doc.remove() or a replication that marked it deleted), while the stale instance is still held in memory.","commonSituations":"Holding an RxDocument in application state or a UI list, deleting it, then patching it from the stale reference; race conditions where a delete replication event lands between fetching a doc and updating it.","solutions":["Check doc.deleted (or doc._data._deleted) before calling modify/patch/save and skip or refresh the reference.","Re-fetch the current document state from the collection instead of reusing a cached instance, and if it does not exist anymore, treat it as removed.","If the intent is to undelete, insert a new document with the same primary key and _deleted: false rather than mutating the deleted instance.","Enable the dev-mode plugin during development so DOC11 shows the full message with the offending document id."],"exampleFix":"// before\nawait staleDoc.patch({ age: 42 });\n\n// after\nconst current = await collection.findOne(staleDoc.primary).exec();\nif (current && !current.deleted) {\n  await current.patch({ age: 42 });\n}","handlingStrategy":"validation","validationCode":"if (doc.deleted) {\n  throw new Error(`document ${doc.primary} is deleted and cannot be modified`);\n}\nawait doc.patch({ age: 42 });","typeGuard":"function isLiveDoc(doc: { deleted: boolean } | null | undefined): doc is { deleted: false } {\n  return !!doc && doc.deleted === false;\n}","tryCatchPattern":"try {\n  await doc.patch(data);\n} catch (err) {\n  if (err?.code === 'DOC11') {\n    // refresh or re-create the document, the held reference is deleted\n    return null;\n  }\n  throw err;\n}","preventionTips":["Do not cache RxDocument instances in long-lived state; re-query before writes.","Check the deleted flag in change-event handlers before applying local updates.","Handle delete events from the replication to evict stale references from UI state."],"tags":["deleted-document","immutable-write","stale-reference"],"backgroundTag":"write-to-deleted-document","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}