Back

Unique index per user on one field?

  • 1
  • Databases
zwelch
15 Apr, 2023, 17:07

Hi! Is it possible to set a unique index per user on one field? I could store another field with the user ID and create a unique index over both fields. But this is not so nice because in this case document security is enabled so the user is known anyway.

TL;DR
The user is asking if it is possible to set a unique index per user on one field in a collection called "fruits". The user wants each user to be able to enter their favorite fruit, but the name of the fruit must be unique for each user. They suggest creating a unique index that includes both the user ID and fruit attributes. The user is aware that they could store another field with the user ID and create a unique index over both fields, but they find this solution less ideal. There is no solution provided in the thread.
Drake
15 Apr, 2023, 17:14

Sorry I'm not quite sure what you mean. What are you trying to do? Make sure no 2 documents have the same value?

zwelch
15 Apr, 2023, 17:24

Let's assume there is a collection "fruits". Every logged in user can deposit his favorite fruits. Each name of a fruit must be unique (apple, banana, pineapple). Therefore a unique index. But another user can also have "banana" as favorite fruit and should be able to enter it. Therefore I need a unique index for one column per user.

Drake
15 Apr, 2023, 17:30

This should be possible with 1 unique index that has both the user id and fruit attributes

zwelch
15 Apr, 2023, 17:36

ok thanks

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more