Back

How to delete all document of collection in one click.

  • 0
  • Databases
  • Flutter
conqueror
8 May, 2023, 18:21

is this will be worked as batch delete ? ```dart class FutureGroup<T> { final List<Completer<T>> _completers = []; final int maxConcurrent;

FutureGroup({this.maxConcurrent = 1});

Future<void> add(Future<T> future) async { if (_completers.length >= maxConcurrent) { await Future.any(_completers.map((c) => c.future)); }

TypeScript
final completer = Completer<T>();
_completers.add(completer);
future.whenComplete(() => _completers.remove(completer));

return completer.complete(await future);

}

Future<void> close() => Future.wait(_completers.map((c) => c.future)); }

Future<void> deleteDocumentsConcurrently(List<String> documentIds) async { final batchFutures = FutureGroup(maxConcurrent: 100);

for (final documentId in documentIds) { await batchFutures.add(database.deleteDocument( databaseId: "6439e7ae4abb3e14f2b1", collectionId: "64444e34a0ce20bc4ac8", documentId: documentId, )); }

await batchFutures.close(); print('All documents deleted'); }````

TL;DR
The user wants to know how to delete all documents in a collection at once. They tried deleting the documents one by one on the server side, but it crashed the server. Another user suggests managing a CSV file server-side or gradually deleting the documents instead of deleting everything at once to avoid impacting app performance. The user asks for a better approach, and it is suggested to use a specific server SDK to delete the documents server-sided. The user expresses concern about passing a large payload when using a cloud function. The suggestion is to learn Dart and write the code themselves rather than relying on others. The user also shares code they generated from ChatG
Drake
8 May, 2023, 18:24

Where did you come up with this?

conqueror
8 May, 2023, 18:26

generated this code from chatgpt, it's working but getting rate limit error if its enable else its deleting all document .

Drake
8 May, 2023, 18:32

I highly recommend you take the time to really understand how dart works and how to write the code yourself. You're going to continuously struggle if you don't take the time to learn.

As mentioned in the other thread, rate limits are expected when executing client-side. See https://appwrite.io/docs/rate-limits

conqueror
8 May, 2023, 18:34

where can i learn this.

Drake
8 May, 2023, 18:35

Maybe you should find a course on dart or take time to write code yourself rather than asking someone else to give you code

D5
8 May, 2023, 19:10

Do that server-sided with a function as mentioned

conqueror
8 May, 2023, 21:36

Thanks for suggestion @D5 , if i use cloud function then have to pass long payload data as result it will give this error "Invalid data: Value must be a valid string and at least 1 chars and no longer than 8192 chars" and same goes for creation of bunch of document creation that is why not using cloud function. hope you got my point.

D5
8 May, 2023, 21:48

You don't need to pass everything as payload, since you can get the data directly from the server instead from getting the data client-sided and then sending everything again to the server/function

conqueror
8 May, 2023, 21:54

is there is any documentation for getting data form server side.

D5
8 May, 2023, 21:58

You can do it as if you were making that client sided, but using a token to allow the function accessing everything

D5
8 May, 2023, 21:59

However, there's a specific server SDK: https://appwrite.io/docs/getting-started-for-server

conqueror
8 May, 2023, 22:00

ok this time got your point,

D5
8 May, 2023, 22:01

Functions don't have rate limits when modifying data, so, probably you will not face any problems related to that

conqueror
8 May, 2023, 22:02

but what about if we are creating bunch of doc, because in this case we are sending data to server.

D5
8 May, 2023, 22:03

Just curious, why do you need to create a bunch of docs instead of creating them one by one?

conqueror
8 May, 2023, 22:03

yes got it.

conqueror
8 May, 2023, 22:04

beause users wants to export all product data to appwrite database in just single.

conqueror
8 May, 2023, 22:06

or i can say want to upload list of product data more then 10k to database so that he don't have to upload every single produt one by one.

conqueror
8 May, 2023, 22:08

this is the usecase

D5
8 May, 2023, 22:11

I think a better approach could be managing a CSV file server-sided or making that gradually instead of everything at once. Note that if an user is making that, others will notice a slower app, so it's better a slow import/export without affecting others, that a fast transfer, while affecting everyone. Maybe @Steven has a better approach?

D5
8 May, 2023, 22:14

Also note that if you allow unlimited import/export transfer rate, someone could intentionally DoS you app easily

conqueror
8 May, 2023, 22:26

noted.

conqueror
8 May, 2023, 22:36

Thanks @D5

conqueror
9 May, 2023, 00:02

tried this as you suggested. but deleting one by one from server side using function is crashing the sever.

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