25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(mongodb): add collection clear actions
二丫讲梵948f979869c3
diff --git a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vueindex a11dd7a525..db21f50ff9 100644--- a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue+++ b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue@@ -364,6 +364,8 @@ import {dropDatabaseLoading,showDropMongoCollectionConfirm,dropMongoCollectionLoading,+ showClearMongoCollectionConfirm,+ clearMongoCollectionLoading,showDropMongoIndexConfirm,dropMongoIndexLoading,showDropAllMongoIndexesConfirm,@@ -619,6 +621,7 @@ const {canDropMongoDatabase,canDropMilvusDatabase,canDropMongoCollection,+ canClearMongoCollection,canDropMilvusCollection,canRenameMongoCollection,canCloneMongoCollection,@@ -673,6 +676,7 @@ const {openDeleteNacosNamespaceConfirm,confirmDeleteNacosNamespace,dropMongoCollection,+ clearMongoCollection,dropMilvusCollection,dropMongoIndex,dropAllMongoIndexes,@@ -689,11 +693,16 @@ const {confirmFlushRedisDb,confirmDropMongoDatabase,confirmDropMongoCollection,+ confirmClearMongoCollection,confirmDropMilvusDatabase,confirmDropMilvusCollection,confirmDropMongoIndex,confirmDropAllMongoIndexes,-} = useSidebarDatabaseSpecificMutationRuntime({ activeNode, connectionStore });+} = useSidebarDatabaseSpecificMutationRuntime({+ activeNode,+ connectionStore,+ refreshDataTabsForTable: (target) => queryStore.refreshDataTabsForTable(target),+});const {isTableNotView,@@ -6052,6 +6061,20 @@ routeDangerDialog(showDropMongoCollectionConfirm, () =>}),);+routeDangerDialog(showClearMongoCollectionConfirm, () =>+ dangerRequest({+ title: t("contextMenu.clearCollectionTitle"),+ message: t("contextMenu.clearCollectionMessage", { name: activeNode.value.label }),+ detailsText: t("contextMenu.clearCollectionDetails"),+ confirmLabel: t("contextMenu.clearCollection"),+ get loading() {+ return clearMongoCollectionLoading.value;+ },+ closeOnConfirm: false,+ confirm: confirmClearMongoCollection,+ }),+);+routeDangerDialog(showDropMongoIndexConfirm, () =>dangerRequest({title: t("contextMenu.confirmDropIndexTitle"),@@ -7171,9 +7194,16 @@ function buildSpecialSidebarMenu(context: SidebarMenuFactoryContext): boolean {{ label: "BSON dump (gzip)", action: () => void exportMongoCollection("bsonGzip") },],});+ const mongoDestructiveActions: ContextMenuItem[] = [];+ if (canClearMongoCollection?.value) {+ mongoDestructiveActions.push({ label: t("contextMenu.clearCollection"), action: clearMongoCollection, icon: Eraser, variant: "destructive" as const });+ }if (canDropMongoCollection.value) {+ mongoDestructiveActions.push({ label: t("contextMenu.dropCollection"), action: dropMongoCollection, icon: Trash2, shortcut: shortcutDelete, variant: "destructive" as const });+ }+ if (mongoDestructiveActions.length > 0) {items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.dropCollection"), action: dropMongoCollection, icon: Trash2, shortcut: shortcutDelete, variant: "destructive" as const });+ items.push(moreActionsSubmenu(mongoDestructiveActions));}return true;}diff --git a/apps/desktop/src/components/sidebar/sidebarTreeDialogState.ts b/apps/desktop/src/components/sidebar/sidebarTreeDialogState.tsindex 9a02c3a049..b2253acea2 100644--- a/apps/desktop/src/components/sidebar/sidebarTreeDialogState.ts+++ b/apps/desktop/src/components/sidebar/sidebarTreeDialogState.ts@@ -120,6 +120,8 @@ export const showDropDatabaseConfirm = ref(false);export const dropDatabaseLoading = ref(false);export const showDropMongoCollectionConfirm = ref(false);export const dropMongoCollectionLoading = ref(false);+export const showClearMongoCollectionConfirm = ref(false);+export const clearMongoCollectionLoading = ref(false);export const showRenameMongoCollectionDialog = ref(false);export const renameMongoCollectionName = ref("");export const renameMongoCollectionError = ref("");diff --git a/apps/desktop/src/composables/useSidebarDatabaseSpecificMutationRuntime.ts b/apps/desktop/src/composables/useSidebarDatabaseSpecificMutationRuntime.tsindex f815dd2846..7a517649b7 100644--- a/apps/desktop/src/composables/useSidebarDatabaseSpecificMutationRuntime.ts+++ b/apps/desktop/src/composables/useSidebarDatabaseSpecificMutationRuntime.ts@@ -21,6 +21,7 @@ import {mongoCreateIndexPreview,mongoDropAllIndexesPreview,mongoDropCollectionPreview,+ mongoClearCollectionPreview,mongoDropIndexFailureCount,mongoDropDatabasePreview,mongoDropIndexPreview,@@ -56,6 +57,8 @@ import {deleteNacosNamespaceLoading,showDropMongoCollectionConfirm,dropMongoCollectionLoading,+ showClearMongoCollectionConfirm,+ clearMongoCollectionLoading,showDropMongoIndexConfirm,dropMongoIndexLoading,showDropAllMongoIndexesConfirm,@@ -101,6 +104,7 @@ import {interface SidebarDatabaseSpecificMutationRuntimeOptions {activeNode: ShallowRef<TreeNode>;connectionStore: ReturnType<typeof useConnectionStore>;+ refreshDataTabsForTable?: (target: { connectionId: string; database: string; schemaCandidates?: Array<string | undefined>; name: string }) => Promise<number>;}function errorMessage(error: unknown): string {@@ -161,6 +165,7 @@ export function useSidebarDatabaseSpecificMutationRuntime(options: SidebarDatabaconst canManageElasticsearchIndex = computed(() => canMutateElasticsearchIndexNode(activeNode.value));const canDropMongoCollection = computed(() => canMutateMongoCollectionNode(activeNode.value));+ const canClearMongoCollection = computed(() => canMutateMongoCollectionNode(activeNode.value) && mongoCollectionKindFromNode(activeNode.value) === "collection");const canDropMilvusCollection = computed(() => activeNode.value.type === "vector-collection" && !!activeNode.value.connectionId && !!activeNode.value.database && connectionStore.getConfig(activeNode.value.connectionId)?.db_type === "milvus");const canRenameMongoCollection = computed(() => canRenameMongoCollectionNode(activeNode.value));const canCloneMongoCollection = computed(() => canCloneMongoCollectionNode(activeNode.value));@@ -934,6 +939,12 @@ export function useSidebarDatabaseSpecificMutationRuntime(options: SidebarDatabashowDropMongoCollectionConfirm.value = true;}+ function clearMongoCollection() {+ if (!canClearMongoCollection.value) return;+ clearMongoCollectionLoading.value = false;+ showClearMongoCollectionConfirm.value = true;+ }+function dropMilvusCollection() {dropMongoCollection();}@@ -1093,6 +1104,43 @@ export function useSidebarDatabaseSpecificMutationRuntime(options: SidebarDataba});}+ async function confirmClearMongoCollection() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ const connectionId = node.connectionId;+ const database = node.database;+ if (!canMutateMongoCollectionNode(node) || mongoCollectionKindFromNode(node) !== "collection" || !connectionId || !database) return;+ const collectionName = node.label;+ await runMongoSidebarMutation({+ connection: connectionStore.getConfig(connectionId),+ database,+ reviewText: mongoClearCollectionPreview(database, collectionName),+ source: t("production.sourceSidebar"),+ loading: clearMongoCollectionLoading,+ beforeExecute: () => connectionStore.ensureConnected(connectionId),+ execute: () => api.mongoDeleteDocuments(connectionId, database, collectionName, "{}", true),+ onSuccess: async () => {+ toast(t("contextMenu.clearCollectionSuccess", { name: collectionName }), 3000);+ showClearMongoCollectionConfirm.value = false;+ try {+ await connectionStore.loadMongoCollections(connectionId, database);+ } catch (error) {+ toast(t("contextMenu.objectDropRefreshFailed", { message: translateBackendError(t, errorMessage(error)) }), 5000);+ }+ try {+ await options.refreshDataTabsForTable?.({+ connectionId,+ database,+ schemaCandidates: [undefined, database],+ name: collectionName,+ });+ } catch (error) {+ toast(t("contextMenu.objectDropRefreshFailed", { message: translateBackendError(t, errorMessage(error)) }), 5000);+ }+ },+ onError: toastMutationError,+ });+ }+async function confirmDropMilvusDatabase() {const node = sidebarDangerTarget.value ?? activeNode.value;const connectionId = node.connectionId;@@ -1234,6 +1282,9 @@ export function useSidebarDatabaseSpecificMutationRuntime(options: SidebarDatabacanDropMongoDatabase,canDropMilvusDatabase,canDropMongoCollection,+ canClearMongoCollection,+ clearMongoCollection,+ confirmClearMongoCollection,canDropMilvusCollection,canRenameMongoCollection,canCloneMongoCollection,diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex b61fed4832..011b77ee3b 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -4795,6 +4795,11 @@ export default {confirmDropCollectionTitle: "Drop Collection",confirmDropCollectionMessage: 'Are you sure you want to drop collection "{name}"? This will permanently delete the collection and all its documents.',dropCollectionSuccess: 'Collection "{name}" dropped',+ clearCollection: "Clear collection",+ clearCollectionTitle: "Clear collection",+ clearCollectionMessage: 'Clear all documents from collection "{name}"? The collection and indexes will be preserved.',+ clearCollectionDetails: "This operation cannot be undone.",+ clearCollectionSuccess: 'Collection "{name}" cleared',createDatabaseNamePlaceholder: "Database name",createDatabaseCharset: "Character set",createDatabaseCharsetPlaceholder: "e.g. utf8mb4",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex a83921ae8d..83effdbf5a 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -4505,6 +4505,11 @@ export default withEnglishFallback({confirmDropCollectionTitle: "Eliminar colección",confirmDropCollectionMessage: '¿Estás seguro de que deseas eliminar la colección "{name}"? Esto borrará permanentemente la colección y todos sus documentos.',dropCollectionSuccess: 'Colección "{name}" eliminada',+ clearCollection: "Vaciar colección",+ clearCollectionTitle: "Vaciar colección",+ clearCollectionMessage: '¿Vaciar todos los documentos de la colección "{name}"? La colección y sus índices se conservarán.',+ clearCollectionDetails: "Esta operación no se puede deshacer.",+ clearCollectionSuccess: 'Colección "{name}" vaciada',createDatabaseNamePlaceholder: "Nombre de la base de datos",createDatabaseCharset: "Conjunto de caracteres",createDatabaseCharsetPlaceholder: "ej. utf8mb4",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex 9ca96b258a..21ee15b3fb 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -4326,6 +4326,11 @@ export default withEnglishFallback({confirmDropCollectionTitle: "Elimina Collection",confirmDropCollectionMessage: 'Sei sicuro di voler eliminare la collection "{name}"? Questa operazione eliminerà permanentemente la collection e tutti i suoi documenti.',dropCollectionSuccess: 'Collection "{name}" eliminata',+ clearCollection: "Svuota collection",+ clearCollectionTitle: "Svuota collection",+ clearCollectionMessage: 'Svuotare tutti i documenti dalla collection "{name}"? La collection e gli indici verranno conservati.',+ clearCollectionDetails: "Questa operazione non può essere annullata.",+ clearCollectionSuccess: 'Collection "{name}" svuotata',createDatabaseNamePlaceholder: "Nome database",createDatabaseCharset: "Set di caratteri",createDatabaseCharsetPlaceholder: "es. utf8mb4",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex 521db3f232..d842279d07 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -4340,6 +4340,11 @@ export default withEnglishFallback({confirmDropCollectionTitle: "コレクションを削除",confirmDropCollectionMessage: "本当にコレクション「{name}」を削除しますか?コレクションとすべてのドキュメントが永久に削除されます。",dropCollectionSuccess: "コレクション「{name}」を削除しました",+ clearCollection: "コレクションを空にする",+ clearCollectionTitle: "コレクションを空にする",+ clearCollectionMessage: "コレクション「{name}」のすべてのドキュメントを削除しますか?コレクションとインデックスは保持されます。",+ clearCollectionDetails: "この操作は元に戻せません。",+ clearCollectionSuccess: "コレクション「{name}」を空にしました",createDatabaseNamePlaceholder: "データベース名",createDatabaseCharset: "文字セット",createDatabaseCharsetPlaceholder: "例: utf8mb4",diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.tsindex 5f95cecd20..59e242a695 100644--- a/apps/desktop/src/i18n/locales/ko.ts+++ b/apps/desktop/src/i18n/locales/ko.ts@@ -4271,6 +4271,11 @@ export default withEnglishFallback({confirmDropCollectionTitle: "컬렉션 삭제",confirmDropCollectionMessage: '컬렉션 "{name}"을(를) 삭제하시겠습니까? 컬렉션과 모든 문서가 영구적으로 삭제됩니다.',dropCollectionSuccess: '컬렉션 "{name}" 삭제됨',+ clearCollection: "컬렉션 비우기",+ clearCollectionTitle: "컬렉션 비우기",+ clearCollectionMessage: '컬렉션 "{name}"의 모든 문서를 비우시겠습니까? 컬렉션과 인덱스는 유지됩니다.',+ clearCollectionDetails: "이 작업은 되돌릴 수 없습니다.",+ clearCollectionSuccess: '컬렉션 "{name}"을(를) 비웠습니다',createDatabaseNamePlaceholder: "데이터베이스 이름",createDatabaseCharset: "문자셋",createDatabaseCharsetPlaceholder: "예: utf8mb4",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex fda1f6e204..2a8e2091bd 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -4322,6 +4322,11 @@ export default withEnglishFallback({confirmDropCollectionTitle: "Remover coleção",confirmDropCollectionMessage: 'Tem certeza de que deseja remover a coleção "{name}"? Isso excluirá permanentemente a coleção e todos os seus documentos.',dropCollectionSuccess: 'Coleção "{name}" removida',+ clearCollection: "Esvaziar coleção",+ clearCollectionTitle: "Esvaziar coleção",+ clearCollectionMessage: 'Esvaziar todos os documentos da coleção "{name}"? A coleção e os índices serão preservados.',+ clearCollectionDetails: "Esta operação não pode ser desfeita.",+ clearCollectionSuccess: 'Coleção "{name}" esvaziada',createDatabaseNamePlaceholder: "Nome do banco de dados",createDatabaseCharset: "Conjunto de caracteres",createDatabaseCharsetPlaceholder: "por exemplo, utf8mb4",diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.tsindex 08007ae279..7c1c4a35e4 100644--- a/apps/desktop/src/i18n/locales/ru.ts+++ b/apps/desktop/src/i18n/locales/ru.ts@@ -4494,6 +4494,11 @@ export default withEnglishFallback({confirmDropCollectionTitle: "Удалить коллекцию",confirmDropCollectionMessage: "Вы уверены, что хотите удалить коллекцию «{name}»? Коллекция и все её документы будут безвозвратно удалены.",dropCollectionSuccess: "Коллекция «{name}» удалена",+ clearCollection: "Очистить коллекцию",+ clearCollectionTitle: "Очистить коллекцию",+ clearCollectionMessage: "Очистить все документы из коллекции «{name}»? Коллекция и индексы будут сохранены.",+ clearCollectionDetails: "Эту операцию нельзя отменить.",+ clearCollectionSuccess: "Коллекция «{name}» очищена",createDatabaseNamePlaceholder: "Имя базы данных",createDatabaseCharset: "Набор символов",createDatabaseCharsetPlaceholder: "например utf8mb4",diff --git a/apps/desktop/src/i18n/locales/th.ts b/apps/desktop/src/i18n/locales/th.tsindex 558ca178be..10873f74d0 100644--- a/apps/desktop/src/i18n/locales/th.ts+++ b/apps/desktop/src/i18n/locales/th.ts@@ -4718,6 +4718,11 @@ export default withEnglishFallback({confirmDropCollectionTitle: "Drop Collection",confirmDropCollectionMessage: "คุณแน่ใจหรือไม่ว่าต้องการ Drop Collection “{name}” การดำเนินการนี้จะลบ Collection และ Document ทั้งหมดอย่างถาวร",dropCollectionSuccess: "Drop Collection “{name}” แล้ว",+ clearCollection: "ล้าง Collection",+ clearCollectionTitle: "ล้าง Collection",+ clearCollectionMessage: "ล้างเอกสารทั้งหมดจาก Collection “{name}” หรือไม่? Collection และดัชนีจะยังคงอยู่",+ clearCollectionDetails: "การดำเนินการนี้ไม่สามารถย้อนกลับได้",+ clearCollectionSuccess: "ล้าง Collection “{name}” แล้ว",createDatabaseNamePlaceholder: "ชื่อฐานข้อมูล",createDatabaseCharset: "Character Set",createDatabaseCharsetPlaceholder: "เช่น utf8mb4",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex afd712648e..a36bc7f88a 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -4725,6 +4725,11 @@ export default withEnglishFallback({confirmDropCollectionTitle: "删除集合",confirmDropCollectionMessage: "确定要删除集合「{name}」吗?这将永久删除该集合及其所有文档。",dropCollectionSuccess: "集合「{name}」已删除",+ clearCollection: "清空集合",+ clearCollectionTitle: "清空集合",+ clearCollectionMessage: "确定要清空集合「{name}」吗?这将删除集合中的全部文档,但保留集合及索引。",+ clearCollectionDetails: "此操作不可逆。",+ clearCollectionSuccess: "集合「{name}」已清空",createDatabaseNamePlaceholder: "数据库名称",createDatabaseCharset: "字符集",createDatabaseCharsetPlaceholder: "例如 utf8mb4",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex 8d99b61259..57355cbf31 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -4328,6 +4328,11 @@ export default withEnglishFallback({confirmDropCollectionTitle: "刪除集合",confirmDropCollectionMessage: "確定要刪除集合「{name}」嗎?這將永久刪除該集合及其所有文件。",dropCollectionSuccess: "集合「{name}」已刪除",+ clearCollection: "清空集合",+ clearCollectionTitle: "清空集合",+ clearCollectionMessage: "確定要清空集合「{name}」嗎?這會刪除集合中的所有文件,但保留集合及索引。",+ clearCollectionDetails: "此操作無法復原。",+ clearCollectionSuccess: "集合「{name}」已清空",createDatabaseNamePlaceholder: "資料庫名稱",createDatabaseCharset: "字元集",createDatabaseCharsetPlaceholder: "例如 utf8mb4",diff --git a/apps/desktop/src/lib/sidebar/mongoCollectionMutation.ts b/apps/desktop/src/lib/sidebar/mongoCollectionMutation.tsindex 9079158be0..9a0de44e72 100644--- a/apps/desktop/src/lib/sidebar/mongoCollectionMutation.ts+++ b/apps/desktop/src/lib/sidebar/mongoCollectionMutation.ts@@ -109,6 +109,10 @@ export function mongoDropCollectionPreview(database: string, collection: string)return `db.getSiblingDB(${JSON.stringify(database)}).getCollection(${JSON.stringify(collection)}).drop()`;}+export function mongoClearCollectionPreview(database: string, collection: string): string {+ return `db.getSiblingDB(${JSON.stringify(database)}).getCollection(${JSON.stringify(collection)}).deleteMany({})`;+}+export function mongoDropDatabasePreview(database: string): string {return `db.getSiblingDB(${JSON.stringify(database)}).dropDatabase()`;}