-
Notifications
You must be signed in to change notification settings - Fork 4.4k
🚀 Feature: Bulk Delete documents in a collection #3520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would also like a route to delete documents by a query. For example, all documents having a certain field set to the same value. This could work similar to fetching documents based on a query. |
This feature would be very helpful, especially during development. Right now it's tedious to delete all documents in a collection, but this happens a lot during various development phases. |
As a workaround right now, I recommend using the Appwrite CLI to maintain your Collections. You can, then, delete your collection to delete everything and then use the Appwrite CLI to deploy your collection to set up all the attributes and indexes. |
We really need this. |
+1 on this 8000 p> |
Would love this feature, too. |
Another way to wipe a collection is with an Appwrite Function: Wipe an Appwrite Collection. |
This is a working workaroun 8000 d but not an elegant way because:
A simple simple checkbox for all the documents would be nice in order to select the ones to delete. |
This is a utility function that helps deletes all documents in a collection without deleting the collection itself (it means attributes, permissions, etc..)
|
This works but API is rate limited 60 requests every 1 minutes per IP address |
You can delete using your own server or appwrite serveless functions Here is the server code that I use to delete all documents in the collection recursively. I have observed that not all docs get deleted when executed a function to delete All docs, so I created this recursive function which does the job to delete all docs I have vercel serverless API endpoints written in TypeScript which delete these docs. Here's the code:- // api/deleteAllDocs/route.ts
import { NextResponse } from "next/server";
import { Client, Databases } from "node-appwrite";
export async function deleteDocs(
db: Databases,
dbId: string,
collId: string,
pass = 1,
) {
if (pass > 10) throw new Error("10 passes reached");
const docListObj = await db.listDocuments(dbId, collId);
const docList = docListObj.documents;
docList.forEach(async doc => await db.deleteDocument(dbId, collId, doc.$id));
const docListObjAgain = await db.listDocuments(dbId, collId);
let lastPass: number;
if (docListObjAgain.documents.length > 0) {
lastPass = await deleteDocs(db, dbId, collId, pass + 1);
} else {
console.log(`deleteDocs() pass count: ${pass}`);
return pass;
}
return lastPass;
}
export async function POST() { //----------------- START---------------------------------//
const client = new Client()
.setEndpoint(process.env.APPWRITE_ENDPOINT!)
.setProject(process.env.APPWRITE_PROJECT_ID!)
.setKey(process.env.APPWRITE_SERVER_KEY!);
const db = new Databases(client);
try {
const passes = await deleteDocs(
db,
process.env.APPWRITE_DATABASE_ID!,
process.env.APPWRITE_COLLECTION_ID!,
);
return NextResponse.json({ success: true, passes });
} catch (e: any) {
console.error(e);
return NextResponse.json({ error: e.message });
}
}
I use my bash curl command to hit this endpoint:- |
I need this feature. 🚀 |
The feature would change my life 🚀 |
🔖 Feature description
Hello,
maybe a button, which deletes all documents in the collection would be pretty nice.
Thanks in advance :D
🎤 Pitch
In my case, I currently getting started with appwrite and building my first project.
Therefore I create many dummy documents and have to delete them all manually.
👀 Have you spent some time to check if this issue has been raised before?
🏢 Have you read the Code of Conduct?
The text was updated successfully, but these errors were encountered: