Back

How to update the value of a document that was just inserted in a database? (Beginner)

  • 0
  • Web
biskuit
19 Nov, 2023, 17:19

Hey everyone, I'm learning how to use Appwrite and so far it's been going really well! I have a question though, say we have a function that is executed whenever a document is added to a collection.

If I wanted to update the value of one of that document's fields based on another of its fields, what would the best course of action be? I tried checking the "req" object's body and performing my conditional logic and it works like a charm, however when attempting to update my new value via databases.updateDocument it seems to do nothing.

I'm pasting my code below...

https://pastebin.com/um5VhfUX

Thank you a lot!

TL;DR
The user is learning how to use Appwrite and wants to update the value of a document when it is inserted into a collection. The user is using the Appwrite JavaScript SDK. They are trying to update the value using `databases.updateDocument`, but it is not working. They are asking for help on the best course of action. However, they have not authenticated to Appwrite. Solution: Authenticate with either `client.setKey()` or `client.setJWT()` before updating the document.
ideclon
19 Nov, 2023, 21:36

You don’t seem to have authenticated to Appwrite anywhere here

ideclon
19 Nov, 2023, 21:37

You need to either use client.setKey() to use server side functions with an API key, or client.setJWT() to authenticate as a user (with a JWT you created on the client side).

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