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
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...