feat(mongodb): support createIndex shell command (#2187)

This commit is contained in:
onenewcode authored and GitHub committed 2026-06-30 21:34:58 +08:00
1 parent 4e012a9dd9
commit b90e4fd64e
17 files changed
+374 -18

No files matched your search

+1
View File
@@ -448,6 +448,7 @@ async fn main() {
.route("/mongo/find-documents", post(routes::mongo::find_documents))
.route("/mongo/server-version", post(routes::mongo::server_version))
.route("/mongo/aggregate-documents", post(routes::mongo::aggregate_documents))
.route("/mongo/create-index", post(routes::mongo::create_index))
.route("/mongo/insert-document", post(routes::mongo::insert_document))
.route("/mongo/insert-documents", post(routes::mongo::insert_documents))
.route("/mongo/update-document", post(routes::mongo::update_document))
+28
View File
@@ -97,6 +97,16 @@ pub struct MongoAggregateRequest {
pub execution_id: Option<String>,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MongoCreateIndexRequest {
pub connection_id: String,
pub database: String,
pub collection: String,
pub keys_json: String,
pub options_json: Option<String>,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MongoInsertRequest {
@@ -286,6 +296,24 @@ pub async fn aggregate_documents(
Ok(Json(serde_json::to_value(result).map_err(|e| AppError(e.to_string()))?))
}
pub async fn create_index(
State(state): State<Arc<WebState>>,
Json(req): Json<MongoCreateIndexRequest>,
) -> Result<Json<serde_json::Value>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Create index").await?;
let name = dbx_core::mongo_ops::mongo_create_index_core(
&state.app,
&req.connection_id,
&req.database,
&req.collection,
&req.keys_json,
req.options_json.as_deref(),
)
.await
.map_err(AppError)?;
Ok(Json(serde_json::json!({ "name": name })))
}
pub async fn insert_document(
State(state): State<Arc<WebState>>,
Json(req): Json<MongoInsertRequest>,