payloadcms/payload · error · QueryError

The following path${results.length === 1 ? '' : 's'} cannot

Error message

The following path${results.length === 1 ? '' : 's'} cannot be queried: ${results.map((err) => err.path).join(', ')}

What it means

Thrown by `validateQueryPaths` as a `QueryError` when one or more `where` paths or operators are not queryable. Payload walks each `where` clause, resolves the field path against the collection/global/version fields, and validates the operator against the field type; any unresolved path or unsupported operator is collected into an `errors` array and, if non-empty, raised. The message lists every offending path.

Source

Thrown at packages/payload/src/database/queryValidation/validateQueryPaths.ts:115

                overrideAccess,
                path,
                policies,
                polymorphicJoin,
                req,
                val,
                versionFields,
              }),
            )
          } else {
            errors.push({ path: `${path}.${operator}` })
          }
        }
      }
    }

    await Promise.all(promises)
    if (errors.length > 0) {
      throw new QueryError(errors)
    }
  }
}

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Read the listed paths in the error and remove or correct each one.
  2. Cross-check field names against the collection config (flattened/indexed fields only).
  3. If filtering nested data, denormalize into a top-level indexed field or query in code after fetch.

Example fix

// before
payload.find({ collection: 'posts', where: { nonExistent: { equals: 'x' } } })
// after
payload.find({ collection: 'posts', where: { title: { equals: 'x' } } })
Defensive patterns

Strategy: try-catch

Validate before calling

// Allowlist queryable field paths before building the where clause
const allowed = new Set(['title', 'status', 'createdAt'])
function cleanWhere(where: Record<string, any>) {
  return Object.fromEntries(Object.entries(where).filter(([k]) => allowed.has(k)))
}

Type guard

function isQueryablePath(path: string, allowed: Set<string>): boolean {
  return allowed.has(path)
}

Try / catch

try {
  await payload.find({ collection, where })
} catch (err) {
  if (err instanceof QueryError) {
    // err.data.errors lists invalid paths — strip them and retry, or 400 the client
  }
  throw err
}

Prevention

When it happens

Trigger: Querying `where[nonExistentField][equals]=x`; using `near` on a non-point field; querying a path inside a block/array that isn't indexed for queries; using an operator the field type disallows (e.g. `contains` on a number).

Common situations: Dynamic client-side filters building paths from user input; querying nested array/block fields that Payload does not expose for where-clauses; version mismatches after renaming a field without updating API consumers.

Related errors


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