{"record":{"id":"e632418cb3ee9869","repo":"pubkey/rxdb","slug":"db3","errorCode":"DB3","errorMessage":"RxDB Error-Code: DB3. 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: DB3\\. 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":351,"sourceCode":"    async addCollections<CreatedCollections = Partial<Collections>>(collectionCreators: {\n        [key in keyof CreatedCollections]: RxCollectionCreator<any>\n    }): Promise<{ [key in keyof CreatedCollections]: RxCollection<any, {}, {}, {}, Reactivity> }> {\n        const jsonSchemas: { [key in keyof CreatedCollections]: RxJsonSchema<any> } = {} as any;\n        const schemas: { [key in keyof CreatedCollections]: RxSchema<any> } = {} as any;\n        const bulkPutDocs: BulkWriteRow<InternalStoreCollectionDocType>[] = [];\n        const useArgsByCollectionName: any = {};\n\n        await Promise.all(\n            Object.entries(collectionCreators).map(async ([name, args]) => {\n                const collectionName: keyof CreatedCollections = name as any;\n                const rxJsonSchema = (args as RxCollectionCreator<any>).schema;\n                jsonSchemas[collectionName] = rxJsonSchema;\n                const schema = createRxSchema(rxJsonSchema, this.hashFunction);\n                schemas[collectionName] = schema;\n\n                // collection already exists\n                if ((this.collections as any)[name]) {\n                    throw newRxError('DB3', {\n                        name\n                    });\n                }\n\n                const collectionNameWithVersion = _collectionNamePrimary(name, rxJsonSchema);\n                const collectionDocData: RxDocumentData<InternalStoreCollectionDocType> = {\n                    id: getPrimaryKeyOfInternalDocument(\n                        collectionNameWithVersion,\n                        INTERNAL_CONTEXT_COLLECTION\n                    ),\n                    key: collectionNameWithVersion,\n                    context: INTERNAL_CONTEXT_COLLECTION,\n                    data: {\n                        name: collectionName as any,\n                        schemaHash: await schema.hash,\n                        schema: schema.jsonSchema,\n                        version: schema.version,\n                        connectedStorages: []","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-database.ts#L333-L369","documentation":"DB3 is thrown by addCollections() when you try to add a collection whose name already exists on the database instance. RxDB keeps one RxCollection per name per database, so re-adding it would create two conflicting instances over the same underlying storage.","triggerScenarios":"Calling db.addCollections({ mycol: {...} }) when db.collections.mycol already exists, e.g. calling addCollections twice with the same definitions, or re-running an init function on an already-initialized database.","commonSituations":"Hot module reload re-running database setup code; calling an initCollections() helper multiple times (e.g. in React StrictMode or repeated component mounts); creating collections eagerly in multiple modules.","solutions":["Check existence before adding: skip addCollections if the collection is already in db.collections.","Split creation from usage: call addCollections once at app startup and reuse the returned collections.","Structure init as an idempotent function guarded by a flag or Promise so repeated calls are no-ops.","In dev hot-reload scenarios, close the old database (db.close()) before recreating it."],"exampleFix":"// before\nawait db.addCollections({ heroes: { schema: heroSchema } });\n// after\nif (!db.collections.heroes) {\n  await db.addCollections({ heroes: { schema: heroSchema } });\n}","handlingStrategy":"validation","validationCode":"if (db.collections.heroes) {\n  return db.collections.heroes;\n}\nawait db.addCollections({ heroes: { schema: heroSchema } });\nreturn db.collections.heroes;","typeGuard":"function isCollectionAdded(db: RxDatabase, name: string): boolean {\n  return name in db.collections;\n}","tryCatchPattern":"try {\n  await db.addCollections(collectionDefs);\n} catch (err) {\n  if (isRxError(err) && err.code === 'DB3') {\n    console.warn('Collections already added, reusing existing instances');\n  } else {\n    throw err;\n  }\n}","preventionTips":["Wrap database initialization in an idempotent, memoized init function (Promise cached in module scope).","Guard addCollections with existence checks per collection name.","In React, create the database outside component render (module scope or singleton) to survive StrictMode double-invocation.","On hot reload, close and recreate the database instead of re-adding collections."],"tags":["duplicate-collection","initialization","configuration"],"backgroundTag":"duplicate-collection-name","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}