Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Compound indexes

default discord avatar
ysione2 years ago
4

Is there a way to describe compound index for collection?



Use case:


Collection has two fields

title

and

value

Collection should have only unique pairs of title and value


Like:


title | value


------------|--------------


email | google


------------|--------------


email | yahoo

  • discord user avatar
    denolfe
    2 years ago

    Not out of the box currently. An option would be to make an additional field that is readOnly, then write a beforeValidate hook that populates it with the 2 values concatenated.

  • default discord avatar
    ysione2 years ago

    I see, thank you

  • default discord avatar
    archvile51682 months ago

    Compound indexes are quite common, any updates in 2025?


    Currently, I'm sneaking in SQL commands in the migration files, and would like to have a more organized way to do this.

  • discord user avatar
    denolfe
    2 months ago

    2 options:


    - If on Postgres, you can use afterSchemaInit

    https://payloadcms.com/docs/database/postgres#afterschemainit

    - You could combine the values of multiple fields into a single one made for searching, and index that one

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.