fix(mongodb): support collection drop shell command
This commit is contained in:
1 parent
315c6e235b
commit
ca9e11217e
14 files changed
+206
-14
No files matched your search
@@ -98,6 +98,13 @@ struct MongoDropIndexesRequest {
|
||||
single: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct MongoDropCollectionRequest {
|
||||
connection_name: String,
|
||||
database: Option<String>,
|
||||
collection: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct MongoInsertDocumentsRequest {
|
||||
connection_name: String,
|
||||
@@ -203,6 +210,8 @@ pub fn start(app_handle: AppHandle, state: Arc<AppState>, data_dir: PathBuf) {
|
||||
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/drop-collection") {
|
||||
handle_mongo_drop_collection_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") {
|
||||
@@ -628,6 +637,29 @@ async fn handle_mongo_drop_indexes_data(state: &Arc<AppState>, body: &str, strea
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_mongo_drop_collection_data(state: &Arc<AppState>, body: &str, stream: &mut tokio::net::TcpStream) {
|
||||
let req: MongoDropCollectionRequest = 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 collection").await {
|
||||
respond_error(stream, "403 Forbidden", &e).await;
|
||||
return;
|
||||
}
|
||||
match dbx_core::mongo_ops::mongo_drop_collection_core(state, &pool_key, &database, &req.collection).await {
|
||||
Ok(()) => respond_json(stream, &serde_json::json!({ "ok": true })).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,
|
||||
|
||||
Reference in new issue
Block a user