Repository navigation
Description
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
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
- Upload multiple files to the Media collection
- Create an item in Test Collection
- Select a couple of Media items in the
Upload Afield - When selecting Media items in the
Upload Bfield, 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
- If you inverse the
filterOptionslogic fromintonot_in- theUpload Bfield will correctly filter for items not selected inUpload Aacross 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
fix(db-mongodb): ensures same level operators are respected (#11087)
github-actions commentedon Feb 11, 2025
🚀 This is included in version v3.23.0
github-actions commentedon Feb 19, 2025
This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.
fix(db-mongodb): ensures same level operators are respected (#11087)