
trying to create bulk product document, using cloud function, sending product data as json to payload

product data is creation if there is less product but if there is lots of product then its giving this error, here is my code if you want to check Future<void> uploadProducts(List<Map<String, dynamic>> products) async {
String payloadString = json.encode({"hallelujah":products});
print(payloadString);
Future result = functions.createExecution(
functionId: 'upload',
data: payloadString,
);

How long ??
And can you share the uploadFunction on what you are trying to do??

more the 10k products

here in my function ```Future<void> start(final req, final res) async { final client = Client(); final db = Databases(client);
final payload = !req.payload?.isEmpty ? jsonDecode(req.payload) : 'No payload provided. Add custom data when executing function.';
if (req.variables['APPWRITE_FUNCTION_ENDPOINT'] == null || req.variables['APPWRITE_FUNCTION_API_KEY'] == null) { print("Environment variables are not set. Function cannot use Appwrite SDK.");
} else { print(payload["hallelujah"]); client .setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT']) .setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID']) .setKey(req.variables['APPWRITE_FUNCTION_API_KEY']) .setSelfSigned(status: true); print(req.variables);
try{
final productData = payload['hallelujah'];
for(var product in productData){
await db.createDocument(
databaseId:'6439e7ae4abb3e14f2b1',
collectionId: '64444e34a0ce20bc4ac8',
documentId: "",
data: product
);
}
}catch(e){
print(e.toString());
}
} res.json({ 'payload': payload, 'areDevelopersAwesome': true, }); } ```

so this should fail cause the documentId is empty and it needs an Id
Secondly the error states that the maximum string size it can accept is around 8192 chars and yours would be certainly way more than that

One more thing since , you are creating bunch of documents why not use the client side function instead of going through a cloud function?

document id is empty for autogeneration of doc id

how to use client side function

You need to use Id.unique() for that for autogeneration


but its creating doc id,

I didn't understand what you are trying to say

there is feature req for it https://github.com/appwrite/appwrite/issues/3051

what you can do it create document concurrenlty, like 100 doc parllerly


should take mostly 1mins max

or possibly 100-110 sec, 10000/100 = 100 ( my math xD)

but for this i have to upload the file then retrieve the data

no no, for reach document creation you automatically does get document response object

i tried this using for loop which is working but taking too much time ``` for (final product in products) {
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'); } }```

yap pls don't use loop, try to make concurrent request

...

ok let me check and try .

that is python code btw
Recommended threads
- User (role: guests) missing scopes (["te...
I keep getting this error: ```AppwriteException: User (role: guests) missing scopes (["teams.read"]) at new AppwriteException (/usr/local/server/src/functio...
- Queries Length Error.
Hi All, I am having a issues across my app with how i am getting data, and just wanted to check if this was an issues with the new changes on appwrite over the...
- The current user is not authorized to pe...
I'm just getting this error while it was working couple minutes ago, my users have permissions to access and create tables data but on some databases I'm just g...
