Back

How to add elements to an array inside a document.

  • 0
  • Databases
  • Flutter
mmjsmohit
12 Jun, 2023, 06:39

There is no method in the documentation which lets us add a single element to a document. The only way is to first get the current array and then add form a new array and send it to the database using updateDocument method. Is there any better solution to this?

TL;DR
To add elements to an array inside a document, you will need to first retrieve the current array, then create a new array by concatenating the current array with the desired element(s), and finally use the `updateDocument` method to save the updated array to the database. There is currently no method in the documentation that allows for directly adding a single element to a document. Consequently, concatenation is the recommended approach for updating the array attribute.
Binyamin
12 Jun, 2023, 12:35

I think you got on the spot. For now, if you want to update array attribute you'll have to concat the current version.

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