Back

[SOLVED] How to update a document without knowing the document ID?

  • 0
  • Databases
  • General
  • Web
kathelia.dokgu
6 Aug, 2023, 17:48

I have a collection that is related to the user account so it has a userId attribute that I use to store the user's ID. A user should only have one record for this collection but I can't seem to make this userId attribute the primary key for the collection. It always creates a document ID that I need to reference. I know that I can always get the document first by searching the userId - and then use the document ID from there to update the values of the document but I was hoping there would be a better way to do this.

TL;DR
The user wants to update a document without knowing the document ID. The solution is to set the document ID as the user ID, making it the primary key.
Binyamin
6 Aug, 2023, 17:50

What you can do is to set the document ID as the user ID and then you have the primary key uses the user ID.

kathelia.dokgu
6 Aug, 2023, 17:51

Oh you mean when I create the document, instead of using ID.unique(), I'll use the user ID instead.. I don't know why I didn't think of that. Thank you!

D5
6 Aug, 2023, 17:52

Does that solves your issue?

kathelia.dokgu
6 Aug, 2023, 17:57

Yes it does. It was my bad for not thinking of such a simple solution.

D5
6 Aug, 2023, 18:02

Great! 😁

D5
6 Aug, 2023, 18:02

[SOLVED] How to update a document without knowing the document ID?

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