Rank 3: Container
its just above the (Future start) , its a long data that is why i did not provided it here.
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 3: Container
its just above the (Future start) , its a long data that is why i did not provided it here.
Admin
2 please tell me how to use payload as i dont have any idea
It's a String...how do you work with strings? What did you pass as data when you executed the function?
Rank 3: Container
paste this same line as map of object not as string { 'image': 'image', 'productName': 'productName', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 12245, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0, }, { 'image': 'image', 'productName': 'productName222', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 456566565, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0, },
Admin
no...it's a string
Rank 3: Container
should i use like this 'image': 'image', 'productName': 'productName222', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 456566565, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0,
Admin
Do you see what's wrong with this code:
final String payload = ""; payload['6439e7ae4abb3e14f2b1'];Admin
You need to pass a valid JSON string and then parse it in your function. what you passed is not a valid JSON string.
Rank 3: Container
should i use like this? , commented the previous line of codedart //databaseId: payload['6439e7ae4abb3e14f2b1'], //collectionId: payload['64444e34a0ce20bc4ac8'], databaseId:'6439e7ae4abb3e14f2b1', collectionId: '64444e34a0ce20bc4ac8',
Rank 3: Container
'image': 'image', 'productName': 'productName', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 12245, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0, }, { 'image': 'image', 'productName': 'productName222', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 456566565, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0, },, APPWRITE_FUNCTION_USER_ID: 64386aeb90452ea0c185, APPWRITE_FUNCTION_JWT: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiI2NDM4NmFlYjkwNDUyZWEwYzE4NSIsInNlc3Npb25JZCI6IjY0Mzg2YWViYTc0NzA1MjcwZGZjIiwiZXhwIjoxNjgzMzk5NzU5fQ.Qksi0AnCQ5BbScKXAV3Ef1LjDMoX2sZoLoDuFLepNyo}{'image': 'image', 'productName': 'productName', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 12245, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0, }, { 'image': 'image', 'productName': 'productName222', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 456566565, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0, },AppwriteException: document_invalid_structure, Invalid document structure: Unknown attribute: "c1667f4f-d1aa-4310-933d-fd4244e30a29" (400)```Rank 3: Container
this is a log from appwrite after execution function
Admin
so you're passing something like this as batchData:
{ "some-uuid-id": { "image": "", "barcode": "" // so on... }, {"another-uuid-id": { "image": "", "barcode": "" // so on... }}This is not a valid document. have you gone through the basics about how to use the Appwrite databases api?
Rank 3: Container
yse i have gone through the database api, and created document also, if i can not use uuid then what is best way to create batch document in a single response
Admin
If you really need to make 1 API request, you can try using graphql: https://appwrite.io/docs/graphql
Admin
Otherwise, it's much simpler to just call createDocument() for each document concurrently
Rank 3: Container
ok, any example so that can perform batch operation.
Admin
Did you read what I linked?
Rank 3: Container
yes, but dont want to use graphql.
Admin
So youre asking about how to execute create document concurrently?
Rank 3: Container
yes, as i used for loop for creating document which is working fine but its taking time and every time its making new request for every new document creation.
Admin
Rank 3: Container
also tried this but not working for long data and taking time dart Future<void> uploadProducts(List<Map<String, dynamic>> products) async { final futures = <Future>[]; for (final product in products) { futures.add(Future(() async { try { final document = await database.createDocument( databaseId: '6439e7ae4abb3e14f2b1', collectionId: collectionId, documentId: '', data: product, ); print('Product ${document.data['productName']} uploaded successfully.'); } catch (e) { print('Error uploading product ${product['productName']}: $e'); } })); } await Future.wait(futures); print('All products uploaded successfully.'); }
Admin
Uh I don't think you create a future like Future(() async { ...})
Admin
NVM I guess you could...
Admin
It will still take time...the point is this will not wait for each document creation before proceeding to the next
Rank 3: Container
ok