#How to create a document if it doesn't exist and return ID if it does?

2 messages · Page 1 of 1 (latest)

glossy cairn
#

I have an app where users can bookmark webpages. When a user bookmarks a page I'd like to save that page in the database, then get the ID of that document and add it to their profile. That's not an issue. What I want to do is if a second user bookmarks the same page I want to check the bookmarks table to see it it already exists. If it does I want to use the existing ID for user 2 and if it doesn't already exist I want to create it and then update the user's profile with the newly created ID. I believe supabase has something like createIfNotExists. Is there something similar in appwrite? I'm using nextjs

torn nimbus
#

In Appwrite you can:

  1. Try to create it and in case you'll get error then fetch the ID.
  2. Try to first fetch it by URL if no results then create it
  3. Move 1 and 2 to a cloud function

That said, it seems like a great feature to have, like Supbase doest.
I didn't find one regarding that issue, you can create one here https://github.com/appwrite/appwrite/issues