Back

How to handle duplicates in Collection

  • 0
  • General
  • Flutter
Binyamin
27 Apr, 2023, 21:51

And docker logs appwrite

TL;DR
Title: Handling duplicates in Collection - Appwrite database is MariaDB. - Consider decentralizing MariaDB into a separate or managed node as your project grows. - Add another field to have a unique index based on two attributes. - Segregate the users' data by permission to track which document belongs to which user. - If storing user ID to any attribute, delete the newly added index, create a new one, and add both attributes to the index. - If a user tries to create a duplicate record, inform them that the attribute already exists. - Error message: "AppwriteException: document_already_exists, Document with the
Binyamin
27 Apr, 2023, 21:51

See what error shows there

new user
27 Apr, 2023, 21:51

but if i dont choose unique then its working fine why?

new user
27 Apr, 2023, 21:53

should i run this in terminal ? docker logs appwrite-worker-databases

Binyamin
27 Apr, 2023, 22:00

Yes

new user
27 Apr, 2023, 22:01

Thanks @Binyamin its working fine, but there is one problem

new user
27 Apr, 2023, 22:02

AppwriteException: document_already_exists, Document with the requested ID already exists. (409)

Binyamin
27 Apr, 2023, 22:02

That's good

Binyamin
27 Apr, 2023, 22:03

Then you should tell the user the that attributes is already exists

new user
27 Apr, 2023, 22:04

if i loged in with different account and want to create same record for that user in that is also giving me error that what i was talking previously.

new user
27 Apr, 2023, 22:07

hope this time you got my point, apologies if i have not explain it properly

Binyamin
27 Apr, 2023, 22:12

Got it

Binyamin
27 Apr, 2023, 22:12

You want it to be unique per user?

new user
27 Apr, 2023, 22:13

yes

Binyamin
27 Apr, 2023, 22:14

Good. Then delete the newly added index.

Then, create a new one and add both attributes to the index

  • user ID
  • the attribute
new user
27 Apr, 2023, 22:16

thanks, as of now i am not storing the user id to any attribute

Binyamin
27 Apr, 2023, 22:16

So how you know which document to which?

new user
27 Apr, 2023, 22:18

you might be amaze as i am segregating the users data by permission

Binyamin
27 Apr, 2023, 22:19

That's fine

Binyamin
27 Apr, 2023, 22:19

But in your case I guess you'll need to add another field to be able to have a unique index that it's based on two attributes

new user
27 Apr, 2023, 22:21

ok, i got your point thanks for your time,

new user
27 Apr, 2023, 22:32

Thanks, this is working

Binyamin
27 Apr, 2023, 22:32

Great

new user
27 Apr, 2023, 22:33

using Appwrite DB or an external database like MariaDB which is better

Binyamin
27 Apr, 2023, 22:52

Appwrite databse is indeed MariaDB If you want and your project grows it might be better to decentraliz the MariaDB into a separate node or a managed one.

You can read a lot about it https://discord.com/channels/564160730845151244/1097119647867863090

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