payloadcms/payload · error · APIError

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

Error message

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

What it means

Thrown by `getEntity` (non-versions branch) when `adapter.collections[collectionSlug]` is undefined — the Mongoose model for the collection was never built, even though the collection config resolves. This indicates the model-construction step of init did not complete for that slug.

Source

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

    )
  }

  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]

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

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

type BaseGetGlobalArgs = {
  adapter: MongooseAdapter
  globalSlug: string
}

interface GetGlobal {
  (args: { versions?: false | undefined } & BaseGetGlobalArgs): {
    globalConfig: SanitizedGlobalConfig
    Model: GlobalModel
  }
  (args: { versions?: true } & BaseGetGlobalArgs): {

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Await `payload.init()` before querying.
  2. Inspect startup logs for model-build errors on the named collection.
  3. Restart to rebuild all models.
  4. Verify there are no duplicate collection slugs in config.

Example fix

// before
const payload = await payload.init() // error swallowed
await payload.find({ collection: 'posts' })
// after
try { await payload.init() } catch (e) { /* surface init errors */ }
Defensive patterns

Strategy: validation

Validate before calling

function assertCollectionModel(adapter, slug) {
  if (!adapter.collections[slug]) throw new Error(`No Mongoose model for ${slug}`)
}

Type guard

const hasCollectionModel = (adapter, s) => Boolean(adapter.collections[s])

Try / catch

try { await payload.find({ collection: slug }) }
catch (e) { if (/collection model with the slug/.test(e.message)) await ensureInit(payload) else throw e }

Prevention

When it happens

Trigger: A standard (non-versions) operation on a collection whose model wasn't constructed during adapter init, or a query issued before models are built.

Common situations: Init race (querying before init resolves); an earlier model-build error for that collection was swallowed; partial init after a thrown error; duplicate slug registration causing one model to be overwritten/missing.

Related errors


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