Back

Can an appwrite array have multiple objects inside?

  • 0
  • Databases
  • Web
  • Cloud
RangerDev
28 May, 2023, 13:46

I would like to create a comments section and store the comments as follows:

TypeScript
[
{
"name" = '',
"comment" = '',
"created" = Date.now()
}
]

and later would like to get the data as comments[0]?.name. I would like to store this as an array in the appwrite document. Is this possible?

TL;DR
The user wants to know if an Appwrite array can have multiple objects inside. The answer is yes, you can have an array of strings in posts and put the document IDs of the related comments. Alternatively, you can put the ID of the post in the comment and fetch all the comments for that post. In Appwrite 1.3, built-in support for relationships was added, but the Appwrite cloud is currently on version 1.1.2. The user wants to create a comments section and store the comments as an array in the appwrite document. This is possible.
Drake
28 May, 2023, 15:43

Are you on Appwrite Cloud?

Drake
28 May, 2023, 15:44

I highly recommend creating a collection of comments.

RangerDev
28 May, 2023, 16:05

yes

RangerDev
28 May, 2023, 16:05

Ok... but how am I supposed to link that to the documents?

RangerDev
28 May, 2023, 16:06

like

RangerDev
28 May, 2023, 16:06

each ducmunet in the posts will also have a document in the comments

RangerDev
28 May, 2023, 16:06

but how am I supposed to like the,?

RangerDev
28 May, 2023, 16:06

like in supabase

Drake
28 May, 2023, 16:27

In Appwrite 1.3, we added built-in support for relationships. Unfortunately, Appwrite cloud is currently on version 1.1.2.

Drake
28 May, 2023, 16:28

For now, you can have an array of strings in posts and put the document IDs of the related comments.

Or you can put the ID of the post in the comment and then you can fetch all the comments for that post.

RangerDev
28 May, 2023, 16:28

okay

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