feat(mongo): add dropIndex and dropIndexes support across full stack

This commit is contained in:
onenewcode authored and GitHub committed 2026-07-01 17:53:09 +08:00
1 parent bb72a58e54
commit 93eeeaa9c6
29 files changed
+1142 -24

No files matched your search

+43
View File
@@ -81,6 +81,15 @@ struct MongoCreateIndexRequest {
options_json: Option<String>,
}
#[derive(Deserialize)]
struct MongoDropIndexesRequest {
connection_name: String,
database: Option<String>,
collection: String,
indexes_json: Option<String>,
single: bool,
}
#[derive(Deserialize)]
struct MongoInsertDocumentsRequest {
connection_name: String,
@@ -182,6 +191,8 @@ pub fn start(app_handle: AppHandle, state: Arc<AppState>, data_dir: PathBuf) {
handle_mongo_aggregate_documents_data(&st, body, &mut stream).await;
} else if first_line.starts_with("POST /data/mongo/create-index") {
handle_mongo_create_index_data(&st, body, &mut stream).await;
} else if first_line.starts_with("POST /data/mongo/drop-indexes") {
handle_mongo_drop_indexes_data(&st, body, &mut stream).await;
} else if first_line.starts_with("POST /data/mongo/insert-documents") {
handle_mongo_insert_documents_data(&st, body, &mut stream).await;
} else if first_line.starts_with("POST /data/mongo/update-documents") {
@@ -554,6 +565,38 @@ async fn handle_mongo_create_index_data(state: &Arc<AppState>, body: &str, strea
}
}
async fn handle_mongo_drop_indexes_data(state: &Arc<AppState>, body: &str, stream: &mut tokio::net::TcpStream) {
let req: MongoDropIndexesRequest = match serde_json::from_str(body) {
Ok(r) => r,
Err(_) => {
respond_error(stream, "400 Bad Request", "Invalid JSON").await;
return;
}
};
let Some((pool_key, database, connection_id)) =
resolve_mongo_pool_key(state, &req.connection_name, req.database, stream).await
else {
return;
};
if let Err(e) = ensure_connection_writable(state, &connection_id, "Drop indexes").await {
respond_error(stream, "403 Forbidden", &e).await;
return;
}
match dbx_core::mongo_ops::mongo_drop_indexes_core(
state,
&pool_key,
&database,
&req.collection,
req.indexes_json.as_deref(),
req.single,
)
.await
{
Ok(result) => respond_json(stream, &result).await,
Err(e) => respond_error(stream, "500 Internal Server Error", &e).await,
}
}
async fn handle_mongo_insert_documents_data(state: &Arc<AppState>, body: &str, stream: &mut tokio::net::TcpStream) {
let req: MongoInsertDocumentsRequest = match serde_json::from_str(body) {
Ok(r) => r,
+21
View File
@@ -160,6 +160,27 @@ pub async fn mongo_create_index(
Ok(serde_json::json!({ "name": name }))
}
#[tauri::command]
pub async fn mongo_drop_indexes(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
collection: String,
indexes_json: Option<String>,
single: bool,
) -> Result<dbx_core::db::mongo_driver::MongoDropIndexesResult, String> {
ensure_connection_writable(&state, &connection_id, "Drop indexes").await?;
dbx_core::mongo_ops::mongo_drop_indexes_core(
&state,
&connection_id,
&database,
&collection,
indexes_json.as_deref(),
single,
)
.await
}
#[tauri::command]
pub async fn mongo_insert_document(
state: State<'_, Arc<AppState>>,