{"record":{"id":"ae3ad84fb6be9e48","repo":"payloadcms/payload","slug":"assertion-for-db-name-of-name-slug-was-faile","errorCode":null,"errorMessage":"Assertion for DB name of ${name} ${slug} was failed.","messagePattern":"Assertion for DB name of (.+?) (.+?) was failed\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/utilities/getDBName.ts","lineNumber":43,"sourceCode":"  let result: null | string = null\n  let custom = config[target]\n\n  if (!custom && target === 'enumName') {\n    custom = config['dbName']\n  }\n\n  if (custom) {\n    result = typeof custom === 'function' ? custom({}) : custom\n  } else {\n    result = name ?? slug ?? null\n  }\n\n  if (versions) {\n    result = `_${result}_versions`\n  }\n\n  if (!result) {\n    throw new APIError(`Assertion for DB name of ${name} ${slug} was failed.`)\n  }\n\n  return result\n}\n","sourceCodeStart":25,"sourceCodeEnd":48,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/utilities/getDBName.ts#L25-L48","documentation":"Thrown by `getDBName` after resolving the name from `custom` (function result or string), then `name`, then `slug`, and applying the `_versions` suffix. If `result` is still falsy, the adapter cannot name the underlying MongoDB collection, so it aborts. The message interpolates `name` and `slug` to help identify the offending entity.","triggerScenarios":"`getDBName` invoked on a config where `dbName` is unset (or its function returns null/empty) AND both `name` and `slug` are null/empty strings.","commonSituations":"A collection/global config constructed programmatically without setting `slug`; a custom `dbName` function that returns undefined under some condition; a config object spread that dropped the slug field.","solutions":["Ensure every collection and global has a non-empty `slug`.","If using `dbName` as a function, always return a non-empty string.","Set `dbName` explicitly on the entity flagged by the `${name} ${slug}` interpolation.","Audit programmatic config builders to guarantee `slug` is assigned."],"exampleFix":"// before\n{ slug: '', fields: [...] }\n// after\n{ slug: 'posts', fields: [...] }","handlingStrategy":"validation","validationCode":"function assertDbName({ name, slug, dbName }) {\n  const resolved = typeof dbName === 'function' ? dbName({}) : (dbName ?? name ?? slug)\n  if (!resolved) throw new Error(`Cannot resolve DB name for slug=${slug}`)\n}","typeGuard":"const hasResolvableDbName = (c) =>\n  Boolean((typeof c.dbName === 'function' ? c.dbName({}) : c.dbName) ?? c.name ?? c.slug)","tryCatchPattern":"try { await payload.init() }\ncatch (e) { if (/Assertion for DB name/.test(e.message)) auditConfigSlugs() else throw e }","preventionTips":["Always set a non-empty slug on every collection and global.","If using a dbName function, ensure it never returns undefined.","Validate programmatic config builders to guarantee slug presence."],"tags":["mongodb","config","db-name","slug"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}