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.

Unique text field?

default discord avatar
raoulyounglast year
5

Is this possible? I am still able to create new items with the same name. Wonder if i am missing something here.


{
      name: "name",
      type: "text",
      required: true,
      unique: true,
    }, 
  • Locally? Can you check your db to ensure the index was created? Sounds like it is not

  • default discord avatar
    raoulyounglast year
    https://github.com/payloadcms/payload/issues/571

    Found something like this, mby i will save your time and check this out 🙂

  • default discord avatar
    thgh.last year

    Got the same issue here. If the field already existed without the unique index, it seems to be ignored.

  • default discord avatar
    raoulyounglast year

    yeah



    drop the collection and create it again with desired attributes, made the magic.

  • default discord avatar
    thgh.last year

    Is there any other way that doesn't loose production data?



    Sign in to mongo express and add the index manually? I'm not so handy with Mongo...

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.