Skip to content

feat(db-mongodb): allow custom id field types#15522

Open
MurzNN wants to merge 1 commit intopayloadcms:mainfrom
Murz-forks:feat/mongoose-custom-id-type
Open

feat(db-mongodb): allow custom id field types#15522
MurzNN wants to merge 1 commit intopayloadcms:mainfrom
Murz-forks:feat/mongoose-custom-id-type

Conversation

@MurzNN
Copy link

@MurzNN MurzNN commented Feb 5, 2026

Summary

Allows setting the custom ID field type in the Mongoose adapter by adding a new argument idType: mongooseIDType and passing it to the function buildSchema().

No test coverage yet, cuz I'm pretty new with the Node.js tests and Payload contributions.

Why?

By default, Payload CMS creates docs using the MongoDB ObjectID as the ID value. But pretty often, the Payload's document IDs are reused in other database types, where the MongoDB's ObjectID value is not native and unclear.

The pretty popular ID value type in most modern databases is UUID, so for some projects, it would be much more convenient to use UUID in all Payload Collections by default.

Yes, we already can customize the ID field, according to the docs https://payloadcms.com/docs/fields/overview#custom-id-fields, but it should be done manually in each collection, so much better to allow choosing the default ID field type for the whole project.

And one more significant limitation of the current Payload Custom ID Field API is that even if we generate the UUID value in JS, it will be stored as a string, wasting 32-36 bytes per id and decreasing the database performance, instead of using the 16-byte binary storage.

This resolves the missing UUID type for MongoDB issue discussed in #13054

How?

  • Adds a new argument idType: mongooseIDType to the function mongooseAdapter().
  • Passes the value to the function buildSchema().
  • Uses the custom type for the _id field schema in the collections.

@MurzNN MurzNN force-pushed the feat/mongoose-custom-id-type branch from 6efd586 to da12084 Compare February 14, 2026 08:13
@MurzNN MurzNN marked this pull request as ready for review February 14, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant