payloadcms/payload · error · APIError
Assertion for DB name of ${name} ${slug} was failed.
Error message
Assertion for DB name of ${name} ${slug} was failed. What it means
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.
Source
Thrown at packages/db-mongodb/src/utilities/getDBName.ts:43
let result: null | string = null
let custom = config[target]
if (!custom && target === 'enumName') {
custom = config['dbName']
}
if (custom) {
result = typeof custom === 'function' ? custom({}) : custom
} else {
result = name ?? slug ?? null
}
if (versions) {
result = `_${result}_versions`
}
if (!result) {
throw new APIError(`Assertion for DB name of ${name} ${slug} was failed.`)
}
return result
}
View on GitHub (pinned to 00c58b35c0)
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.
Example fix
// before
{ slug: '', fields: [...] }
// after
{ slug: 'posts', fields: [...] } Defensive patterns
Strategy: validation
Validate before calling
function assertDbName({ name, slug, dbName }) {
const resolved = typeof dbName === 'function' ? dbName({}) : (dbName ?? name ?? slug)
if (!resolved) throw new Error(`Cannot resolve DB name for slug=${slug}`)
} Type guard
const hasResolvableDbName = (c) =>
Boolean((typeof c.dbName === 'function' ? c.dbName({}) : c.dbName) ?? c.name ?? c.slug) Try / catch
try { await payload.init() }
catch (e) { if (/Assertion for DB name/.test(e.message)) auditConfigSlugs() else throw e } Prevention
- 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.
When it happens
Trigger: `getDBName` invoked on a config where `dbName` is unset (or its function returns null/empty) AND both `name` and `slug` are null/empty strings.
Common situations: 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.
Related errors
- Global with the slug ${globalSlug} was not found
- Collection with the slug ${globalSlug} was not found
- ERROR: Failed to retrieve collection with the slug "${collec
- ERROR: Failed to retrieve global with the slug "${globalSlug
- Fields are not initialized.
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/ae3ad84fb6be9e48.
Report an issue: GitHub.