{"record":{"id":"18f3ef66fc677f82","repo":"hcengineering/platform","slug":"not-implemented-18f3ef","errorCode":null,"errorMessage":"Not implemented","messagePattern":"Not implemented","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/account/src/collections/mongo.ts","lineNumber":198,"sourceCode":"  async insertOne (data: Partial<T>): Promise<K extends keyof T ? T[K] : undefined> {\n    const toInsert: Partial<T> & {\n      _id?: string\n    } = { ...data }\n    const idKey = this.idKey\n\n    if (idKey !== undefined) {\n      const key = new UUID().toJSON()\n      toInsert[idKey] = data[idKey] ?? (key as any)\n      toInsert._id = toInsert._id ?? toInsert[idKey]\n    }\n\n    await this.collection.insertOne(toInsert as OptionalUnlessRequiredId<T>)\n\n    return (idKey !== undefined ? toInsert[idKey] : undefined) as K extends keyof T ? T[K] : undefined\n  }\n\n  async insertMany (data: Array<Partial<T>>): Promise<K extends keyof T ? Array<T[K]> : undefined> {\n    throw new Error('Not implemented')\n  }\n\n  async update (query: Query<T>, ops: Operations<T>): Promise<void> {\n    const resOps: any = { $set: {} }\n\n    for (const key of Object.keys(ops)) {\n      switch (key) {\n        case '$inc': {\n          resOps.$inc = ops.$inc\n          break\n        }\n        default: {\n          resOps.$set[key] = ops[key]\n        }\n      }\n    }\n    await this.collection.updateMany(getFilteredQuery(query) as Filter<T>, resOps)\n  }","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/collections/mongo.ts#L180-L216","documentation":"The Mongo collection adapter implements insertOne but leaves insertMany as an explicit stub that always throws 'Not implemented'. Any bulk-insert path (batchAssignWorkspace, batchAssignWorkspacePermission) that relies on insertMany will fail unconditionally on the Mongo-backed collection.","triggerScenarios":"Calling insertMany on the Mongo collection adapter, directly or indirectly through batchAssignWorkspace or batchAssignWorkspacePermission when accounts are stored in MongoDB.","commonSituations":"Running workspace batch assignment in a mongo-backed deployment; switching the account store backend from an implementation that supported insertMany to mongo; assuming parity between collection adapter backends.","solutions":["Implement insertMany in the mongo adapter using this.collection.insertMany(mapped docs)","As a workaround, loop over the array and call insertOne per item","Route batch assignment workloads to a backend whose collection supports insertMany","Add a unit test asserting insertMany works (or is explicitly unsupported) per backend"],"exampleFix":"// before\nasync insertMany (data: Array<Partial<T>>): Promise<K extends keyof T ? Array<T[K]> : undefined> {\n  throw new Error('Not implemented')\n}\n// after\nasync insertMany (data: Array<Partial<T>>): Promise<K extends keyof T ? Array<T[K]> : undefined> {\n  await this.collection.insertMany(data as OptionalUnlessRequiredId<T>[])\n  return data.map((d) => d[idKey as keyof T]) as any\n}","handlingStrategy":"fallback","validationCode":"if (typeof (collection as any).insertMany !== 'function' || isMongoCollectionAdapter(collection)) {\n  await Promise.all(data.map((d) => collection.insert(d)))\n} else {\n  await collection.insertMany(data)\n}","typeGuard":"function supportsInsertMany<T, K extends keyof T>(c: Collection<T, K>): c is Collection<T, K> & { insertMany(d: Array<Partial<T>>): Promise<any> } {\n  try { c.insertMany([]); return true } catch (e) { return (e as Error).message !== 'Not implemented' }\n}","tryCatchPattern":"try {\n  await collection.insertMany(records)\n} catch (err) {\n  if ((err as Error).message === 'Not implemented') {\n    for (const r of records) await collection.insert(r) // per-item fallback\n    return\n  }\n  throw err\n}","preventionTips":["Wrap bulk inserts behind a helper that falls back to per-item insertOne","Add contract tests that every collection backend implements insertMany","Check backend feature parity before switching the account store implementation","Track/fix the stub in server/account/src/collections/mongo.ts:198 rather than relying on the fallback"],"tags":["not-implemented","mongodb","bulk-insert"],"backgroundTag":"method-not-implemented","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}