Back

Getting old document before update

  • 0
  • Databases
  • Functions
enoy
20 Feb, 2023, 14:59

Is it possible to create a function that listens to an database document update event and retrieve it's old values? Or do I need a workaround for that?

TL;DR
The user wants to retrieve an old document before it was updated. One solution suggested is to have the user make the update using a function instead of directly calling the database service. Another solution is to create a new document with "_old" suffix. There is also a feature request for this issue on GitHub. It is suggested to create a duplicate collection for the old documents. The user asks if it is possible to create a function that listens to a database document update event and retrieve its old values.
Drake
20 Feb, 2023, 17:25

There was a feature request for something like this: https://github.com/appwrite/appwrite/issues/3294 You might want to 👍🏼 the issue.

One thing you can do is create a duplicate collection that contains the old document.

What exactly are you trying to do, though? What's your use case?

enoy
27 Feb, 2023, 19:19

I need to verify if a change made by the user is valid. So yeah... I worked around the problem by creating a new doc with _old suffix... Since the user has no create permission for the collection at all this is safe to use i guess.

enoy
27 Feb, 2023, 19:31

Gave the issue a 👍

Drake
27 Feb, 2023, 19:50

sounds like you're doing input validation? In that case, I would have the user make the update by executing a function instead of calling the database service directly. the function would do validation and reject the request if it's not valid.

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