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
- Migration and Function glitch
I am trying to migrate from non pro appwrite project to pro appwrite project all my data but it's stuck in processing.
- Unable to signup to appwrite cloud
When attempting to create an online cloud account on appwrite.io, I get the following message : "This email address must already be in its canonical form. Pleas...
- Email address must be in its canonical f...
Hello, Recently I was trying to signup with my GitHub account with appwrite account for availing the student benifits but while trying to signup I saw such erro...