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
- Got message for auto payment of 15usd fo...
how did this happen? 1. i claimed my 50usd credits via jsm hackathon - https://hackathon.jsmastery.pro/ 2. it asked me which org. to apply the credits on, i se...
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...