{"record":{"id":"65c9809304973e61","repo":"payloadcms/payload","slug":"either-collection-or-globalslug-must-be-passed","errorCode":null,"errorMessage":"Either collection or globalSlug must be passed.","messagePattern":"Either collection or globalSlug must be passed\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/deleteVersions.ts","lineNumber":36,"sourceCode":"\n  if (globalSlug) {\n    const { globalConfig, Model } = getGlobal({\n      adapter: this,\n      globalSlug,\n      versions: true,\n    })\n    fields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\n    VersionsModel = Model\n  } else if (collectionSlug) {\n    const { collectionConfig, Model } = getCollection({\n      adapter: this,\n      collectionSlug,\n      versions: true,\n    })\n    fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n    VersionsModel = Model\n  } else {\n    throw new APIError('Either collection or globalSlug must be passed.')\n  }\n\n  const query = await buildQuery({\n    adapter: this,\n    fields,\n    locale,\n    where,\n  })\n\n  const session = await getSession(this, req)\n\n  await VersionsModel.deleteMany(query, { session })\n}\n","sourceCodeStart":18,"sourceCodeEnd":50,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/deleteVersions.ts#L18-L50","documentation":"deleteVersions requires exactly one target: a collection slug or a global slug. If neither is supplied it throws an APIError. This is an internal DB-layer precondition; the framework normally guarantees one is passed.","triggerScenarios":"A programmatic call to payload.db.deleteVersions (or an internal versions-deletion path) invoked with an args object missing both `collection` and `globalSlug`. Reachable via custom jobs/hooks that call the adapter directly with an empty selector.","commonSituations":"Custom script/job that calls deleteVersions without specifying the entity; a bug in a plugin that forwards an incomplete args object.","solutions":["Pass either `{ collection: 'posts', where: {...} }` or `{ globalSlug: 'header', where: {...} }` to deleteVersions.","If calling from a hook, derive the slug from the hook context rather than passing undefined.","Audit custom plugins/jobs that invoke the DB adapter's deleteVersions for missing args.","Wrap the call in a guard that throws a clearer domain error before reaching the adapter."],"exampleFix":"// before\nawait payload.db.deleteVersions({ where: { id: { equals: x } } })\n\n// after\nawait payload.db.deleteVersions({\n  collection: 'posts',\n  where: { id: { equals: x } },\n})","handlingStrategy":"validation","validationCode":"function assertDeleteVersionsTarget(args: { collection?: string; globalSlug?: string }) {\n  if (!args.collection && !args.globalSlug) {\n    throw new Error('deleteVersions requires `collection` or `globalSlug`')\n  }\n}","typeGuard":"function hasDeleteTarget(args: unknown): args is { collection?: string; globalSlug?: string } {\n  if (typeof args !== 'object' || args === null) return false\n  const a = args as { collection?: unknown; globalSlug?: unknown }\n  return typeof a.collection === 'string' || typeof a.globalSlug === 'string'\n}","tryCatchPattern":null,"preventionTips":["Always pass a collection or globalSlug when calling deleteVersions.","Derive the slug from hook context rather than hardcoding.","Wrap custom jobs that touch the adapter with an args assertion."],"tags":["db-mongodb","versions","api-error","validation"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}