Back

error while adding new documents

  • 0
  • Databases
mitsy0_0
1 Jun, 2023, 21:12

This is how I am adding documents in my collection, but my function is failing to execute Is there something wrong in this approach?

TypeScript
    for i in range(len(name_list)):

      result = databases.create_document('64776905e1fxxxx', '64776913a740bxxxx', ID.unique(), data = {
                  'name': name_list[i],
                'logo': logo_list[i],
                'title': title_list[i],
                'location': location_list[i]
            },)
TL;DR
User is encountering an error while adding new documents. They are asking if there is something wrong with their approach. The error message they provided is "list index out of range." Some users suggest outputting the length of each list to ensure they all have the same length. There is a link provided with an example of wrapping the code with a try-catch block to send back the error. The user mentions that there is no error in the logs. A possible solution could be to check the length of each list and ensure they match.
Binyamin
1 Jun, 2023, 21:12

What's the error?

mitsy0_0
1 Jun, 2023, 21:13

no error

mitsy0_0
1 Jun, 2023, 21:13

its just failing

mitsy0_0
1 Jun, 2023, 21:13
Binyamin
1 Jun, 2023, 21:15

Can you try wrap your code with try catch So the error will be send back? Like this https://discord.com/channels/564160730845151244/1113545780863701013/1113549759416897708

Binyamin
1 Jun, 2023, 21:15

There's no info in the any of the logs tabs?

mitsy0_0
1 Jun, 2023, 21:17

nopw

mitsy0_0
1 Jun, 2023, 21:17

when I use try catch

mitsy0_0
1 Jun, 2023, 21:17

it returns

mitsy0_0
1 Jun, 2023, 21:17

{"message":"list index out of range","success":false}

Binyamin
1 Jun, 2023, 21:19

That's good It means that one of the lists doesn't contain as many items as name_list list. Try to output the len of each list. to be sure they all have the same length.

mitsy0_0
1 Jun, 2023, 21:21

oh yes you are right, thanks, that was dumbπŸ˜…

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