payloadcms/payload · error · APIError

ERROR: Failed to retrieve collection with the slug "${collec

Error message

ERROR: Failed to retrieve collection with the slug "${collectionSlug}". Does not exist.

What it means

Thrown by `getEntity` — the central slug→config+model resolver used by nearly every MongoDB adapter operation — when `adapter.payload.collections[collectionSlug]` is undefined. The collection is not registered at runtime, so no config/model lookup can proceed.

Source

Thrown at packages/db-mongodb/src/utilities/getEntity.ts:25

export const getCollection = ({
  adapter,
  collectionSlug,
  versions = false,
}: {
  adapter: MongooseAdapter
  collectionSlug: string
  versions?: boolean
}): {
  collectionConfig: SanitizedCollectionConfig
  customIDType: Collection['customIDType']

  Model: CollectionModel
} => {
  const collection = adapter.payload.collections[collectionSlug]

  if (!collection) {
    throw new APIError(
      `ERROR: Failed to retrieve collection with the slug "${collectionSlug}". Does not exist.`,
    )
  }

  if (versions) {
    const Model = adapter.versions[collectionSlug]

    if (!Model) {
      throw new APIError(
        `ERROR: Failed to retrieve collection version model with the slug "${collectionSlug}". Does not exist.`,
      )
    }

    return { collectionConfig: collection.config, customIDType: collection.customIDType, Model }
  }

  const Model = adapter.collections[collectionSlug]

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Verify the slug exactly matches a `slug` in `payload.config.collections`.
  2. Confirm the collection is registered and `payload.init()` resolved.
  3. For dynamic slugs, validate against `Object.keys(payload.collections)` first.
  4. Check REST route spelling against the configured collection slug.

Example fix

// before
await payload.findByID({ collection: 'post', id })
// after
await payload.findByID({ collection: 'posts', id })
Defensive patterns

Strategy: validation

Validate before calling

function assertCollectionExists(payload, slug) {
  if (!payload.collections[slug]) throw new Error(`Collection not registered: ${slug}`)
}

Type guard

const isRegisteredCollection = (payload, s) =>
  typeof s === 'string' && Object.prototype.hasOwnProperty.call(payload.collections, s)

Try / catch

try { await payload.find({ collection: slug, ... }) }
catch (e) { if (/Failed to retrieve collection with the slug/.test(e.message)) handleUnknownCollection(slug) else throw e }

Prevention

When it happens

Trigger: Any Mongo adapter operation (find, findOne, create, update, delete, count, etc.) with a `collectionSlug` that is not a key of `payload.collections`.

Common situations: Slug typo; collection renamed without migrating callers; wrong/multi config loaded; querying before init resolves; REST request to a wrong endpoint path.

Related errors


AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12). Data as JSON: /api/errors/f1d33ed0d2491f60. Report an issue: GitHub.