I'm calling this from a cloud function, deletes a few documents. But not all of them. Why ?
def delete_all_documents(database, collection_id): docsRef = database.list_documents(MASTER_DATABASE_ID,collection_id) for doc in docsRef["documents"]: database.delete_document(MASTER_DATABASE_ID, collection_id, doc["$id"])
Are you using any queries when using list_documents? If I remember correctly, it defaults to a limit of 25 when a limit has not been set using queries
No queries
list all douments
You'll need to implement something like this.
async cleanCollection(databaseId, collectionId) {
let response;
const queries = [
Query.lessThan('$createdAt', getExpiryDate()),
Query.limit(25),
];
do {
response = await this.databases.listDocuments(
databaseId,
collectionId,
queries
);
await Promise.all(
response.documents.map((document) =>
this.databases.deleteDocument(databaseId, collectionId, document.$id)
)
);
} while (response.documents.length > 0);
}
This function specifically deletes items after x date, but it should be easy to just update it to delete everything in a collection.
Thanks!
So this should work on python right ?
def delete_all_documents(database, collection_id):
docsRef = database.list_documents(MASTER_DATABASE_ID,collection_id)
while docsRef["total"]>0:
for doc in docsRef["documents"]:
database.delete_document(MASTER_DATABASE_ID, collection_id, doc["$id"])
docsRef = database.list_documents(MASTER_DATABASE_ID,collection_id)
Without any experience in Python it's hard to tell you with confidence it will work, maybe someone with more knowledge there can jump in.
Recommended threads
- Functions executed by events does not ap...
Hello, Running self-hosted Appwrite version 1.9.0 (with console 7.8.26). When functions are triggered by an event (eg. databases.\*tables.\*.rows.\*.create) doe...
- Updating GitHub App access throws error
Steps to reproduce - 1. Have some private repos allowed on the install access 2. New Site/Func > Connect GitHub > see the side card saying `Missing a repo` > cl...
- New Build not visible on Domain
I pushed some new code to my Appwrite Site and the build succeeded and is shown as active. Yet, I can only see the new version of the site on Appwrite's provide...