pubkey/rxdb · error · RxError
DOC11
DOC11
Error message
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
What it means
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.
Source
Thrown at src/rx-document.ts:381
return docData;
});
},
/**
* saves the new document-data
* and handles the events
*/
async _saveData<RxDocType>(
this: RxDocument<RxDocType>,
newData: RxDocumentWriteData<RxDocType>,
oldData: RxDocumentData<RxDocType>
): Promise<RxDocument<RxDocType>> {
isWriteAllowed(this.collection);
newData = flatClone(newData);
// deleted documents cannot be changed
if (this._data._deleted) {
throw newRxError('DOC11', {
id: this.primary,
document: this
});
}
await beforeDocumentUpdateWrite(this.collection, newData, oldData);
const writeRows = [{
previous: oldData,
document: newData
}];
const writeResult = await this.collection.storageInstance.bulkWrite(writeRows, 'rx-document-save-data');
const isError = writeResult.error[0];
throwIfIsStorageWriteError(this.collection, this.primary, newData, isError);
await this.collection._runHooks('post', 'save', newData, this);
return this.collection._docCache.getCachedRxDocument(
getWrittenDocumentsFromBulkWriteResponse(
this.collection.schema.primaryPath,View on GitHub (pinned to af6fb65f94)
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.
Example fix
// before
await staleDoc.patch({ age: 42 });
// after
const current = await collection.findOne(staleDoc.primary).exec();
if (current && !current.deleted) {
await current.patch({ age: 42 });
} Defensive patterns
Strategy: validation
Validate before calling
if (doc.deleted) {
throw new Error(`document ${doc.primary} is deleted and cannot be modified`);
}
await doc.patch({ age: 42 }); Type guard
function isLiveDoc(doc: { deleted: boolean } | null | undefined): doc is { deleted: false } {
return !!doc && doc.deleted === false;
} Try / catch
try {
await doc.patch(data);
} catch (err) {
if (err?.code === 'DOC11') {
// refresh or re-create the document, the held reference is deleted
return null;
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
AI-assisted analysis of pubkey/rxdb@af6fb65f94 (2026-08-31).
Data as JSON: /api/errors/1d135050c135d09f.
Report an issue: GitHub.