#[SOLVED]how to array list in appwrite attribute

142 messages · Page 1 of 1 (latest)

quasi light
#

s

silent meteor
#

Attribute > New > Select Data Type > Select Array

quasi light
silent meteor
#

Afaik, the return value might be a String. You'll have to convert it into an array first.

quasi light
#

it is an array

#

Is there anything wrong

idle bone
quasi light
#

This is appwrite file

idle bone
#

what does cartItem attribute say?

#

also, can you tell me if cartItem is always a number?

quasi light
#

It returns all the document from addtocart collection

quasi light
idle bone
#

well cartitems is expecting a string and you're not giving that

quasi light
#

how do i do that

#

cartitems is string

idle bone
#

so cartItem is an array in your code right?

quasi light
#

yes

idle bone
#

why is it a string

#

shouldn't it be []

quasi light
quasi light
idle bone
#

could you send an image of all attributes in there?

quasi light
idle bone
quasi light
#

This is addtocart collection

idle bone
#

your browser array console.log

#

i need that

idle bone
quasi light
#

which attribute

idle bone
#

just the first object in that array

quasi light
idle bone
#

not in your appwrite instance

#

in your browser console

quasi light
#

okay

quasi light
idle bone
quasi light
#

no

idle bone
#

from where then?

quasi light
#

listdocument

#

can i call you and explain all this

idle bone
#

huh

#

i mean no need, but listDocuments shouldn't give you this error

#

are you sure it's from listing?

quasi light
#

yes

idle bone
quasi light
#

u mean array size

idle bone
#

the size, yes

#

in the appwrite attribute

quasi light
idle bone
quasi light
#

Let me explain u the code

idle bone
# quasi light

You see this?
Go here, delete the attribute and recreate it with a lower size

silent meteor
idle bone
#

correct

quasi light
#

yes

idle bone
#

but his listing does not work at all, so my guess is it's empty

quasi light
#

it is not empty

idle bone
#

you could male a second collection

quasi light
#

inside the array there is data

idle bone
quasi light
#

yes

idle bone
#

do you need that data? or can you recreate it

quasi light
#

i dont need the data but

#

deleting the attributes might cause the issue

idle bone
#

then just delete that attribute and recreate it with a lower size

quasi light
#

the n what will be the further process

quasi light
#

i need to do that again

#

that's why

#

let me send you my code screenshot okay

#

okay or not

idle bone
#

I mean, sure, but i doubt i can do anything with it

quasi light
#

and this is appwrite config

idle bone
#

cannot do anything with this

idle bone
quasi light
#

bro you messing thing up

silent meteor
quasi light
#

you cannot come with proper solution

idle bone
#

is giving him the error lol

idle bone
quasi light
idle bone
#

so his entire code does not matter, just that aopwrite has a connection and it's fetching

idle bone
quasi light
#

yes

idle bone
#

bro

#

why did you say listdocuments then

silent meteor
#

exactly

quasi light
#

due to cartItem value

idle bone
quasi light
#

the error is occuring

#

due to cartItem value

silent meteor
#

a get method has nothing to do with what the type is as long as the data type matches the attribute type.

quasi light
#

which is in the form of an array

idle bone
quasi light
#

that causing the issue

#

else everything works fine

idle bone
#

i don't think he knows himself 😂

silent meteor
idle bone
#

yep

silent meteor
quasi light
#

which one

silent meteor
#

hang on a minute.

silent meteor
quasi light
#

okay

silent meteor
#

cartItem is an array in your code, right?

quasi light
#

yes

silent meteor
#

and it seems its an Object of a custom type and not string.

quasi light
#

and just need that array list to orderItem database collection

quasi light
#

guide me through solution

#

please

silent meteor
#

each object inside your array must be converted to a string I guess.

atomic carbon
#

Where you're using createDocument the value for cartItem needs to look something like this:
cartItem: [JSON.stringify(cartItem)]

idle bone
#

the stringify might actually be it

atomic carbon
#

From what I can tell, it looks like you're trying to insert an entire object into a string[], you'll just need to remember to use JSON.parse() when fetching that cartItem data later

silent meteor
#

If the cart item objects are more than just strings, OP is better off using relations.

#

atleast the exact structure would be maintained.

atomic carbon
#

Relationships could work here as well, definitely! Could even just reference an ID of another document if you wanted to wait until relationships were out of beta

silent meteor
#

This is true, referencing the ID is a go to as I've had the whole collection freezing sometimes when an item with relations is deleted.

atomic carbon
#

Yeah, I've had some performance issues with relationships in the past so I tend to stick with just using IDs until it's out of beta

idle bone
#

same

idle bone
#

@quasi light Did Ryan's fix resolve your issue?

quasi light
#

Yes it worked

idle bone
# quasi light Yes it worked

Great!

Would you mind marking it as solved by adding [SOLVED] to the beginning of the title?

Have an appwrite day!

quasi light
#

but one issue is there

idle bone
#

What's up?

quasi light
#

the data is saved in incorrect form

#

not in proper json file