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
raoulyoung2 years ago
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,
    }, 
  • discord user avatar
    jarrod_not_jared
    2 years ago

    Locally? Can you check your db to ensure the index was created? Sounds like it is not

  • default discord avatar
    raoulyoung2 years ago
    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.2 years ago

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

  • default discord avatar
    raoulyoung2 years ago

    yeah



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

  • default discord avatar
    thgh.2 years ago

    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.