{"record":{"id":"75d57525b86c7cfb","repo":"payloadcms/payload","slug":"missing-where-query-of-documents-to-delete","errorCode":null,"errorMessage":"Missing 'where' query of documents to delete.","messagePattern":"Missing 'where' query of documents to delete\\.","errorType":"http","errorClass":"APIError","httpStatus":400,"severity":"error","filePath":"packages/payload/src/collections/operations/delete.ts","lineNumber":93,"sourceCode":"      depth,\n      overrideAccess,\n      overrideLock,\n      populate,\n      req: {\n        fallbackLocale,\n        locale,\n        payload: { config },\n        payload,\n      },\n      req,\n      select: incomingSelect,\n      showHiddenFields,\n      trash = false,\n      where,\n    } = args\n\n    if (!where) {\n      throw new APIError(\"Missing 'where' query of documents to delete.\", httpStatus.BAD_REQUEST)\n    }\n\n    // /////////////////////////////////////\n    // Access\n    // /////////////////////////////////////\n\n    let accessResult: AccessResult\n\n    if (!overrideAccess) {\n      accessResult = await executeAccess(\n        { slug: collectionConfig.slug, req },\n        collectionConfig.access.delete,\n      )\n    }\n\n    await validateQueryPaths({\n      collectionConfig,\n      overrideAccess: overrideAccess!,","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/delete.ts#L75-L111","documentation":"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.","triggerScenarios":"Calling `payload.delete({ collection })` with no `where` clause at all.","commonSituations":"Caller assumed empty `where` deletes nothing or everything; a refactor dropped the `where` argument; an optional `where` variable resolved to undefined.","solutions":["Provide an explicit `where` clause such as `{ id: { in: ids } }`.","If deleting all matching docs is truly intended, pass a non-empty where (e.g. `{ status: { equals: 'x' } }`) deliberately."],"exampleFix":"// before\nawait payload.delete({ collection: 'logs' })\n// after\nawait payload.delete({ collection: 'logs', where: { createdAt: { less_than: cutoff } } })","handlingStrategy":"validation","validationCode":"function requireWhere(where) {\n  if (!where || (typeof where === 'object' && Object.keys(where).length === 0)) {\n    throw new Error('A non-empty where clause is required for bulk delete')\n  }\n}","typeGuard":"function hasWhere(where): where is Record<string, unknown> {\n  return !!where && typeof where === 'object'\n}","tryCatchPattern":null,"preventionTips":["Always pass an explicit `where` to `payload.delete`.","Never call delete with an optional/possibly-empty where."],"tags":["delete","validation","where-query","safety"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}