Back

[SOLVED] Prevent creating a document that has a property identical to another

  • 0
  • Databases
  • Web
loup
25 Jun, 2023, 14:45

is it possible to prevent creating a document that has a property (example: username) identical to another document?

TL;DR
The user is asking how to prevent creating a document with a property identical to another document. They mention using getDocument instead of listDocuments for faster performance. They suggest using the same custom id for both the user and document id. However, they don't want to have the same username in two different documents. They ask if they need to check if the username is available before creating an account. The solution suggested is to use a unique index to prevent creating a document with a duplicate property.
Drake
25 Jun, 2023, 14:47

You can use a unique index for that: https://appwrite.io/docs/databases#indexes

loup
25 Jun, 2023, 18:06

so I have to check if the username is available before creating an account right (and create a document) ?

Drake
25 Jun, 2023, 18:06

You mean ID? Or email? The API would return an error if one already exists

loup
25 Jun, 2023, 18:08

No username. I mean my usercollection look like that (with some example) :

loup
25 Jun, 2023, 18:09

When I create a new user, I add a document with the usernameand extra info like language, bio, avatar etc...

loup
25 Jun, 2023, 18:09

But I dont want to have the same username in two different document

Drake
25 Jun, 2023, 18:22

How about use the same custom id when creating the user and for the document id of this users collection?

loup
25 Jun, 2023, 18:40

So I thought it was easier to retrieve a document by its id rather than looking for the document that has a certain userId. I thought it was faster in terms of performance and server load, isn't it?

Drake
25 Jun, 2023, 23:55

Yes, It's faster to do getDocument rather than listDocumebts

loup
26 Jun, 2023, 14:44

[SOLVED] Prevent creating a document that has a property identical to another

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