Rank 2: Process
What if there are lakhs of documents in a collection. Is there a way to delete all of them using a cloud function with python runtime ?
Votes
0
Replies
17
Participants
Unknown
Messages
18
Rank 2: Process
What if there are lakhs of documents in a collection. Is there a way to delete all of them using a cloud function with python runtime ?
Rank 2: Process
Yes, you can delete all documents in an Appwrite collection using a cloud function with the Python runtime. Here's a high-level overview of the steps involved:
Initialize the Appwrite Client: You need to initialize the Appwrite Client in your Python code. This involves setting the endpoint, project ID, and API key.
List Documents: Use the listDocuments method from the Databases service to retrieve all the documents in the collection.
Delete Documents: Iterate through the list of documents and delete each one using the deleteDocument method from the Databases service.
Here's a sample Python code snippet to achieve this:
from appwrite.client import Clientfrom appwrite.services.databases import Databases
client = Client()client.set_endpoint('https://cloud.appwrite.io/v1')client.set_project('<YOUR_PROJECT_ID>')client.set_key('<YOUR_API_KEY>')
databases = Databases(client)
# List documentsdocuments = databases.list_documents('<DATABASE_ID>', '<COLLECTION_ID>')['documents']
# Delete documentsfor document in documents: databases.delete_document('<DATABASE_ID>', '<COLLECTION_ID>', document['$id'])Please replace <YOUR_PROJECT_ID>, <YOUR_API_KEY>, <DATABASE_ID>, and <COLLECTION_ID> with your actual project and collection details.
For more detailed information, you can refer to the Appwrite documentation on Cloud Functions and Python Quick Starts.
Rank 2: Process
hello ji ye lo ap ka solution
Rank 2: Process
Thank you so much. Are you sure this is the most efficient solution? Are there any alternatives ? @Drake
Rank 2: Process
I dont know. I searched on google and found this
Rank 2: Process
Thanks anyways @Ryan
Rank 2: Process
No problem
This looks like it was written with ChatGPT 😅
Rank 2: Process
nah, Perplexity AI 😎
Rank 2: Process
it is ChatGPT but with internet access
Right - because ChatGPT wouldn’t know about Appwrite. But there’s also Bing chat, which is ChatGPT with Internet access - and I think if you pay for GPT-4, you’ll also get Internet?
Rank 2: Process
yes, that is correct. And ChatGPT knows about Appwrite, but very limited info. and idk why but I only use bing chat for the free image gen and I aint payin for GPT-4
Rank 2: Process
@Drake I used this method but when there were many documents, some of the documents didnt get deleted.
This is an old function but the logic should be fine. This does what you're wanting and should delete all documents in a collection. I know it's node but it shouldn't be too difficult to translate that logic to python. If you need any help lmk.
Rank 2: Process
@Kenny Dont you think the function's timeout has anythimng to do with this ?
It could depending on how many documents you have, you can always increase the timeout?
Admin
Please don't tag people as it can be very disruptive. You have plenty of community members here answering you already
Rank 2: Process
Okayy