{"record":{"id":"991e55d0830dee36","repo":"pubkey/rxdb","slug":"snh-991e55","errorCode":"SNH","errorMessage":"RxDB Error-Code: SNH. 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: SNH\\. 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-database.ts","lineNumber":316,"sourceCode":"            return;\n        }\n        this.emittedEventBulkIds.add(changeEventBulk.id);\n        this.eventBulks$.next(changeEventBulk);\n    }\n\n    /**\n     * removes the collection-doc from the internalStore\n     */\n    async removeCollectionDoc(name: string, schema: any): Promise<void> {\n        const doc = await getSingleDocument(\n            this.internalStore,\n            getPrimaryKeyOfInternalDocument(\n                _collectionNamePrimary(name, schema),\n                INTERNAL_CONTEXT_COLLECTION\n            )\n        );\n        if (!doc) {\n            throw newRxError('SNH', { name, schema });\n        }\n        const writeDoc = flatCloneDocWithMeta(doc);\n        writeDoc._deleted = true;\n\n        await this.internalStore.bulkWrite([{\n            document: writeDoc,\n            previous: doc\n        }], 'rx-database-remove-collection');\n    }\n\n    /**\n     * creates multiple RxCollections at once\n     * to be much faster by saving db txs and doing stuff in bulk-operations\n     * This function is not called often, but mostly in the critical path at the initial page load\n     * So it must be as fast as possible.\n     */\n    async addCollections<CreatedCollections = Partial<Collections>>(collectionCreators: {\n        [key in keyof CreatedCollections]: RxCollectionCreator<any>","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-database.ts#L298-L334","documentation":"SNH ('should not happen') is thrown by removeCollectionDoc when the internal collection document for the given collection name and schema cannot be found in the database's internal store. Removing a collection's internal doc requires that the collection was previously registered; a missing doc means the bookkeeping entry does not exist, so the invariant 'must exist before removal' is violated.","triggerScenarios":"Calling db.removeCollectionDoc(name, schema) (usually internally from db.removeCollection) for a collection whose internal document was never written, was already deleted, or where name/schema do not match the registered collection (e.g. wrong version).","commonSituations":"Calling removeCollection twice on the same collection; removing a collection in a different database instance than the one that created it; name or schema version mismatch after migrations; corrupted or manually cleared internal store.","solutions":["Only remove collections that currently exist in db.collections (check before calling).","Ensure the schema passed matches the collection as registered (same name and version).","Do not call removeCollectionDoc directly; use db.removeCollection(name) which resolves the correct schema.","If the collection was already removed, treat the operation as done instead of calling removal again."],"exampleFix":"// before\nawait db.removeCollectionDoc('heroes', schema);\n// after\nif (db.collections.heroes) {\n  await db.removeCollection('heroes');\n}","handlingStrategy":"validation","validationCode":"if (!db.collections[name]) {\n  return;\n}\nawait db.removeCollection(name);","typeGuard":"function collectionExists(db: RxDatabase, name: string): boolean {\n  return Object.prototype.hasOwnProperty.call(db.collections, name);\n}","tryCatchPattern":"try {\n  await db.removeCollection(name);\n} catch (err) {\n  if (isRxError(err) && err.code === 'SNH') {\n    console.warn('Collection internal doc missing; treating as already removed');\n  } else {\n    throw err;\n  }\n}","preventionTips":["Make removal idempotent: check db.collections before removing.","Never call removeCollectionDoc directly; use the public removeCollection API.","Avoid removing collections across different RxDatabase instances for the same storage."],"tags":["internal-state","assertion","collection-removal"],"backgroundTag":"internal-invariant-violated","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}