hcengineering/platform · error
Not implemented
Error message
Not implemented
What it means
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.
Source
Thrown at server/account/src/collections/mongo.ts:198
async insertOne (data: Partial<T>): Promise<K extends keyof T ? T[K] : undefined> {
const toInsert: Partial<T> & {
_id?: string
} = { ...data }
const idKey = this.idKey
if (idKey !== undefined) {
const key = new UUID().toJSON()
toInsert[idKey] = data[idKey] ?? (key as any)
toInsert._id = toInsert._id ?? toInsert[idKey]
}
await this.collection.insertOne(toInsert as OptionalUnlessRequiredId<T>)
return (idKey !== undefined ? toInsert[idKey] : undefined) as K extends keyof T ? T[K] : undefined
}
async insertMany (data: Array<Partial<T>>): Promise<K extends keyof T ? Array<T[K]> : undefined> {
throw new Error('Not implemented')
}
async update (query: Query<T>, ops: Operations<T>): Promise<void> {
const resOps: any = { $set: {} }
for (const key of Object.keys(ops)) {
switch (key) {
case '$inc': {
resOps.$inc = ops.$inc
break
}
default: {
resOps.$set[key] = ops[key]
}
}
}
await this.collection.updateMany(getFilteredQuery(query) as Filter<T>, resOps)
}View on GitHub (pinned to 63e28dc964)
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
Example fix
// before
async insertMany (data: Array<Partial<T>>): Promise<K extends keyof T ? Array<T[K]> : undefined> {
throw new Error('Not implemented')
}
// after
async insertMany (data: Array<Partial<T>>): Promise<K extends keyof T ? Array<T[K]> : undefined> {
await this.collection.insertMany(data as OptionalUnlessRequiredId<T>[])
return data.map((d) => d[idKey as keyof T]) as any
} Defensive patterns
Strategy: fallback
Validate before calling
if (typeof (collection as any).insertMany !== 'function' || isMongoCollectionAdapter(collection)) {
await Promise.all(data.map((d) => collection.insert(d)))
} else {
await collection.insertMany(data)
} Type guard
function supportsInsertMany<T, K extends keyof T>(c: Collection<T, K>): c is Collection<T, K> & { insertMany(d: Array<Partial<T>>): Promise<any> } {
try { c.insertMany([]); return true } catch (e) { return (e as Error).message !== 'Not implemented' }
} Try / catch
try {
await collection.insertMany(records)
} catch (err) {
if ((err as Error).message === 'Not implemented') {
for (const r of records) await collection.insert(r) // per-item fallback
return
}
throw err
} Prevention
- 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
When it happens
Trigger: Calling insertMany on the Mongo collection adapter, directly or indirectly through batchAssignWorkspace or batchAssignWorkspacePermission when accounts are stored in MongoDB.
Common situations: 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.
Related errors
- Not implemented
- Can only move accounts from mongodb for now
- Type and value are required
- workspaceUuid is required
- Workspace with uuid ${data.workspaceUuid} not found
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/18f3ef66fc677f82.
Report an issue: GitHub.