
Can i add or remove one item from array over the simple code for update docment?

Same as any other array, it's not possible at the moment.

Would you have any suggestions on how to add/remove to an array without bumping into race conditions?

Don't use arrays 😅

So there is basically no way to manage this then? I'm mostly asking this because I have to increase a counter but then only way to do so is to get the document and update it with a higher count which wouldn't work because of race conditions. Would it be possible to use an appwrite function and mark it as sync somehow so it will execute once the previous execution is done?

For that counter, I would implement a sort of locking mechanism using unique indexes or something like that. For example, let's say I have a likes attribute on a collection. Id create a likesLocks collection. When updating the like, I would
- create a document with the same id in the likesLocks collection
- Update the like count
- Delete the lock document

So what would happen when two parts of the code try to update the like count in this case? The second execution will try to create the lock while the lock already exists? So then the second execution will fail and has to retry until succeeding? I guess that could work 🤔

so when i want to update the array relationship. How can i do for this?

and when i create new document with having the related collection, is I just add the id of related document to array?

You could do something like Steven suggested:
- create a document in a collection called 'locks' by an unique index that's unique for your action for example: 'update-relationship-array'
- execute your action: add/remove from the array and update the document with the updated array
- remove the lock document Now step 1 could fail because the lock already exists so your code should catch this and try again to create the lock document until either retrying too many times or until the lock is deleted. This way you can add and remove from arrays without bumping into issues with race conditions
Recommended threads
- How to pass session from browser to a mo...
I have a self-hosted Appwrite container. I also have a www page (A) which should acts as login page for different www services (B). User click login in B, is re...
- Two steps signIn with one user:
'm using appwrite to try two phase login, step 1: await account.createAnonymousSession(); or final appwriteUser = await account.create( ...
- Registering new flutter app
Hi, ive got an already build flutter app which works in development with appwrite. but with the built version i get an error that the client is not registered. ...
