CollectionConfig removes indexes field #4601
Replies: 5 comments
-
We removed this collection config when we added database adapters. Since the type was based on MongoDB it didn't make sense to keep it there since it wouldn't work for other adapters. The recommended way to handle this now is to add indexes inside of migrations. This is something we should document and maybe we can revisit adding the What do you think? |
Beta Was this translation helpful? Give feedback.
-
@DanRibbens In order to migrate to the latest version (v2.2.2), how to adjust the code of 'indexes' for the previous v1.11.0 version? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hey @liulian-13, We will be adding the You'll need to create the migration, see https://payloadcms.com/docs/database/migrations. Use Payload to access your models and call You will commit your migration and then you will need to run the migration on your production instance or other environments that depend on the indexes being there. I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
@DanRibbens Is the indexes property supported in the new version? If it is already supported, please let me know here, thank you. |
Beta Was this translation helpful? Give feedback.
-
I've converted this to a discussion as I don't think we are going to add index creation back to the config like we had done in 1.x If you don't want to deal with db migrations you also have the option of adding custom index creating to the config in the In your project or a plugin, you can create indexes using: // payload.config.ts
// ..
onInit: ({payload}) => {
payload.db.collections[collectionSlug].index({ fields: { carMake: 1, name: 1 }, options: { unique: true }})
payload.db.collections[collectionSlug]index({ fields: {carMake: 1, fullname: 1 }, options: { unique: true }})
}), This can also be done in plugins that add collections that need to also specify indexes. |
Beta Was this translation helpful? Give feedback.
-
Link to reproduction
No response
Describe the Bug
The indexes field has been removed from CollectionConfig in the latest version, but I can't find any description on how to migrate it in the documentation?
To Reproduce
When upgrading from v1.11.1 to v2.2.2, I found that the previously supported indexes field is no longer supported.

Payload Version
2.2.2
Adapters and Plugins
No response
Beta Was this translation helpful? Give feedback.
All reactions