Back

I have array attribute in one collection , how i can add and delete any element in this attribute

  • 0
  • Android
Shubham
19 Aug, 2023, 10:00

I have array attribute in one collection , how i can add and delete any element in this attribute with just one update call .

TL;DR
The user wants to know how to add and delete elements in an array attribute of a collection. The suggested solution is to fetch the document, manipulate the array as needed, and then update the document. Currently, it is not possible to achieve this with just one call, but there is a related issue on GitHub that may provide a solution in the future.
safwan
19 Aug, 2023, 10:52

It isn't possible with just one call, yet. For now, you need to fetch the document, manipulate the array as you want, and send it back.

safwan
19 Aug, 2023, 10:54

Related issue. Make sure to 👍 https://github.com/appwrite/appwrite/issues/2531

Shubham
19 Aug, 2023, 11:03

for that we have to do 3 calls one by one

Shubham
19 Aug, 2023, 11:06

first i will upload one document , then we will get that id , then we will get arrays documents and then add new id to this array , and then we have to update this

safwan
19 Aug, 2023, 12:27

yep so you do this:

  1. getDocument or listDocuments (with a query)
  2. change things in the array as needed
  3. updateDocument
Shubham
19 Aug, 2023, 20:29
TypeScript
   2. get Document and get array
    3. add document id in this array 
   4.update document  
safwan
19 Aug, 2023, 20:30

what do you mean by this:

  1. save document and get id
safwan
19 Aug, 2023, 20:31

just fetch the document, get the attribute and update it as needed, then run updateDocument

Shubham
20 Aug, 2023, 08:05

yes thats wht i do

Shubham
20 Aug, 2023, 08:07

when i query any collections with Query.equal("name", ["id1","id3","id2"]) , is it possible that i will get all document in order according to this array i passed in query

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