payloadcms/payload · error · APIError

Missing 'where' query of documents to delete.

Error message

Missing 'where' query of documents to delete.

What it means

Inside `deleteOperation`, after destructuring args, if `where` is falsy it throws `APIError` (400). Bulk delete intentionally refuses to run without an explicit filter to prevent accidentally wiping an entire collection.

Source

Thrown at packages/payload/src/collections/operations/delete.ts:93

      depth,
      overrideAccess,
      overrideLock,
      populate,
      req: {
        fallbackLocale,
        locale,
        payload: { config },
        payload,
      },
      req,
      select: incomingSelect,
      showHiddenFields,
      trash = false,
      where,
    } = args

    if (!where) {
      throw new APIError("Missing 'where' query of documents to delete.", httpStatus.BAD_REQUEST)
    }

    // /////////////////////////////////////
    // Access
    // /////////////////////////////////////

    let accessResult: AccessResult

    if (!overrideAccess) {
      accessResult = await executeAccess(
        { slug: collectionConfig.slug, req },
        collectionConfig.access.delete,
      )
    }

    await validateQueryPaths({
      collectionConfig,
      overrideAccess: overrideAccess!,

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Provide an explicit `where` clause such as `{ id: { in: ids } }`.
  2. If deleting all matching docs is truly intended, pass a non-empty where (e.g. `{ status: { equals: 'x' } }`) deliberately.

Example fix

// before
await payload.delete({ collection: 'logs' })
// after
await payload.delete({ collection: 'logs', where: { createdAt: { less_than: cutoff } } })
Defensive patterns

Strategy: validation

Validate before calling

function requireWhere(where) {
  if (!where || (typeof where === 'object' && Object.keys(where).length === 0)) {
    throw new Error('A non-empty where clause is required for bulk delete')
  }
}

Type guard

function hasWhere(where): where is Record<string, unknown> {
  return !!where && typeof where === 'object'
}

Prevention

When it happens

Trigger: Calling `payload.delete({ collection })` with no `where` clause at all.

Common situations: Caller assumed empty `where` deletes nothing or everything; a refactor dropped the `where` argument; an optional `where` variable resolved to undefined.

Related errors


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