Skip to content

Cannot filter on id field via filterOptions callback #10944

Closed

Description

@damnsamn

Describe the Bug

We're currently unable to filter upload field results by their id in the filterOptions callback. This seems to be true of MongoDB installations, but not of PostgreSQL installations, where this behaviour works as expected.


Consider the below field config:

{
  name: "uploadField",
  type: 'upload',
  relationTo: 'media',
  filterOptions: {
    id: {
      in: ['idA', 'idB'],
    },
  },
}

In a Postgres installation of Payload, this upload field will display Media items whose IDs are in the given array.
In a Mongo installation of Payload, this upload field will display all Media items without filtering.


Potentially related:
The "Custom ID Field" functionality appears to not function as documented. When testing this issue, I attempted to change the ID to a number (copied the snippet from the docs) to better align with Postgres to see if that affected anything, which returned the following error upon saving a new Media item:

[14:48:06] ERROR: document must have an _id before saving
    err: {
      "type": "MongooseError",
      "message": "document must have an _id before saving",
      "stack":
          MongooseError: document must have an _id before saving
              at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]_@[email protected]/node_modules/mongoose/lib/model.js:314:18)
              at process.processTicksAndRejections (node:internal/process/task_queues:85:11)
    }

Link to the code that reproduces this issue

https://github.com/damnsamn/blank-payload-project/tree/issue/filter-options-id

Reproduction Steps

Context

Our TestCollection consists of an upload (hasMany:true) field uploadA, and an upload (hasMany:false) field uploadB.

uploadB is configured to filter based on uploadA's current value. uploadB should only be able to select from items already selected in uploadA.

Steps

  1. Upload multiple files to the Media collection
  2. Create an item in Test Collection
  3. Select a couple of Media items in the Upload A field
  4. When selecting Media items in the Upload B field, note that we are not seeing a filtered subset of Media, but the entire collection.
    • When testing with a Postgres installation, where IDs are numbers instead of strings, this step will behave as expected
  5. If you inverse the filterOptions logic from in to not_in - the Upload B field will correctly filter for items not selected in Upload A across both Mongo and Postgres installations.

Which area(s) are affected? (Select all that apply)

area: core, db-mongodb

Environment Info

Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 10.0.0
Relevant Packages:
  payload: 3.19.0
  next: 15.1.5
  @payloadcms/db-mongodb: 3.19.0
  @payloadcms/email-nodemailer: 3.19.0
  @payloadcms/graphql: 3.19.0
  @payloadcms/next/utilities: 3.19.0
  @payloadcms/payload-cloud: 3.19.0
  @payloadcms/richtext-lexical: 3.19.0
  @payloadcms/translations: 3.19.0
  @payloadcms/ui/shared: 3.19.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.0.0: Mon Aug 12 20:52:31 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6030
  Available memory (MB): 18432
  Available CPU cores: 12

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Feb 3, 2025
  2. added and removed
    validate-reproduction
    on Feb 3, 2025
  3. removed
    status: needs-triage
    on Feb 10, 2025
  4. github-actions commented on Feb 11, 2025

    @github-actions
    Contributor

    🚀 This is included in version v3.23.0

  5. github-actions commented on Feb 19, 2025

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  6. locked as resolved and limited conversation to collaborators on Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions