Back

Database and collection issue or guidance.

  • 0
  • Databases
  • Web
LAKSHYA
12 Jan, 2024, 13:17

I have an collection of objects inside the array like this. example- const [arrray, setarray] = useState<any[]>([ { link: "", title: "", description: "", tags: [], images: null, status: "pending", category: "", ownerId: "", type: "Website Link", }, { link: "", title: "", description: "", tags: [], images: null, status: "pending", category: "", ownerId: "", type: "Website Link", }, ])

Is their any way that i can store this in appwrite database as it is. because user can add multiple objects up to 25 objects inside the array. after that what i want to do it is i wanted to show that data in card step by step as it is stored . I hope you understood so how i can implement this in appwrite . Or i have to store every object individually?.please help me with the approach.

TL;DR
The developer is asking if they can store an array of objects in an Appwrite database as it is. They have an array of objects with various properties and want to display them in cards. They mention that Appwrite doesn't allow storing objects or arrays directly. The solution is to convert the array to a string using `json.stringify` before pushing it to the database and then parse the string back to an array using `json.parse` when retrieving it. They can have an attribute that is a string and push the array as a string.
vishwa
12 Jan, 2024, 13:19

Hey you could have an attribute which is a string and push the array as a string

vishwa
12 Jan, 2024, 13:20

And when you retrieve it from the db you could just parse the string

vishwa
12 Jan, 2024, 13:22

So while pushing the array , you should convert the array to a string by using json.stringify

vishwa
12 Jan, 2024, 13:22

and while retrieving you could use json.parse to convert the string back to an array

vishwa
12 Jan, 2024, 13:23

Hope this makes sense @LAKSHYA

vishwa
12 Jan, 2024, 13:25

BTW for your reference appwrite doesn't allow to store objects or arrays as it is

LAKSHYA
12 Jan, 2024, 13:27

okay this makes sense 🤔. Let me try this approach.

LAKSHYA
12 Jan, 2024, 13:27

thankyou

vishwa
12 Jan, 2024, 13:27

Sure, lemme know if it works

LAKSHYA
12 Jan, 2024, 13:27

sure

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