This change makes so that data that exists in MongoDB but isn't defined in the Payload config won't be included to `payload.find` / `payload.db.find` calls. Now we strip all the additional keys. Consider you have a field named `secretField` that's also `hidden: true` (or `read: () => false`) that contains some sensitive data. Then you removed this field from the database and as for now with the MongoDB adapter this field will be included to the Local API / REST API results without any consideration, as Payload doesn't know about it anymore. This also fixes https://github.com/payloadcms/payload/issues/11542 if you removed / renamed a relationship field from the schema, Payload won't sanitize ObjectIDs back to strings anymore. Ideally you should create a migration script that completely removes the deleted field from the database with `$unset`, but people rarely do this. If you still need to keep those fields to the result, this PR allows you to do this with the new `allowAdditionalKeys: true` flag.
Payload MongoDB Adapter
Official MongoDB adapter for Payload.
Installation
npm install @payloadcms/db-mongodb
Usage
import { buildConfig } from 'payload'
import { mongooseAdapter } from '@payloadcms/db-mongodb'
export default buildConfig({
db: mongooseAdapter({
url: process.env.DATABASE_URI,
}),
// ...rest of config
})
More detailed usage can be found in the Payload Docs.