Unique text field?

default discord avatar
Raoul
2 months 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
    Payload Team
    2 months ago

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

  • default discord avatar
    Raoul
    2 months 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 months ago

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

  • default discord avatar
    Raoul
    2 months ago

    yeah



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

  • default discord avatar
    thgh.
    2 months 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...

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.