Back

issue with creating a document, with string[] attribute.

  • 0
  • Databases
ICE
9 Mar, 2024, 02:04

I have the following json object

[ { "productName": "Apple iPhone 16", "productPrice": 1090, "productDetails": "Apple iPhone 16, Blue color 128GB", "productAvailable": true, "qty": 0, "$id": "65e637fb3c024dad0313", "$createdAt": "2024-03-04T21:07:07.246+00:00", "$updatedAt": "2024-03-05T20:27:45.703+00:00", "$permissions": [], "$databaseId": "smartCartDB", "$collectionId": "Products" }, { "productName": "Samsung S24", "productPrice": 987, "productDetails": "Samsung S24, Green with 12GB RAM", "productAvailable": true, "qty": 0, "$id": "65e65b5231fb9c3a32b5", "$createdAt": "2024-03-04T23:37:54.205+00:00", "$updatedAt": "2024-03-05T20:16:29.733+00:00", "$permissions": [], "$databaseId": "smartCartDB", "$collectionId": "Products" }, { "productName": "Mato Neo 40 Edge", "productPrice": 499, "productDetails": "Mato Neo 40 Edge, 256GB, 50MP camera, Wireless charging", "productAvailable": true, "qty": 5, "$id": "65e77de1399b0d3a3d61", "$createdAt": "2024-03-05T20:17:37.236+00:00", "$updatedAt": "2024-03-05T20:29:22.418+00:00", "$permissions": [], "$databaseId": "smartCartDB", "$collectionId": "Products" } ]

I am trying to add these items into the Orders document, which have following attributes, orderStatus: String orderItems: string[] orderPayment: string.

How can i convert my json object as array and create a document. I have tried Object.entries. but it didnt help.

TL;DR
Developers are discussing how to convert a JSON object into an array of strings to create a document with specific attributes. They suggest passing an array directly and not using Object.entries.
Steven
9 Mar, 2024, 02:06

You need to pass it an array of strings

ICE
9 Mar, 2024, 02:07

How can convert my JSON object into array of strings

Steven
9 Mar, 2024, 02:07

Did you try googling that?

ICE
9 Mar, 2024, 02:08

I am trying it 🙂

ICE
9 Mar, 2024, 02:08

I tried with Object.entires. method

ICE
9 Mar, 2024, 02:08

it didnt help

Steven
9 Mar, 2024, 02:08

That said, Appwrite's database is flat. And you would nest data using relationships

Steven
9 Mar, 2024, 02:10

I wouldn't use that. Not sure where you found that answer.

Steven
9 Mar, 2024, 02:50

What else have you found?

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