feat(mongodb): support bulkWrite
This commit is contained in:
1 parent
3f3c21aae9
commit
f78dc1ba16
25 files changed
+1089
-18
No files matched your search
@@ -968,6 +968,7 @@ async fn main() {
|
||||
.route("/mongo/update-document", post(routes::mongo::update_document))
|
||||
.route("/mongo/update-documents", post(routes::mongo::update_documents))
|
||||
.route("/mongo/replace-document", post(routes::mongo::replace_document))
|
||||
.route("/mongo/bulk-write", post(routes::mongo::bulk_write))
|
||||
.route("/mongo/delete-document", post(routes::mongo::delete_document))
|
||||
.route("/mongo/delete-documents", post(routes::mongo::delete_documents))
|
||||
.route("/mongo/find-one-and-update", post(routes::mongo::find_one_and_update))
|
||||
|
||||
@@ -269,6 +269,16 @@ pub struct MongoReplaceDocumentRequest {
|
||||
pub options_json: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MongoBulkWriteRequest {
|
||||
pub connection_id: String,
|
||||
pub database: String,
|
||||
pub collection: String,
|
||||
pub operations_json: String,
|
||||
pub options_json: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MongoDeleteDocumentsRequest {
|
||||
@@ -846,6 +856,36 @@ pub async fn replace_document(
|
||||
Ok(Json(serde_json::json!({ "affected_rows": result })))
|
||||
}
|
||||
|
||||
pub async fn bulk_write(
|
||||
State(state): State<Arc<WebState>>,
|
||||
headers: HeaderMap,
|
||||
Json(req): Json<MongoBulkWriteRequest>,
|
||||
) -> Result<Json<dbx_core::db::mongo_driver::MongoBulkWriteResult>, AppError> {
|
||||
let database = super::mcp_policy::resolve_database(&state, &headers, &req.connection_id, &req.database).await?;
|
||||
let command = dbx_core::mongo_shell::MongoCommand::BulkWrite {
|
||||
collection: req.collection.clone(),
|
||||
operations: req.operations_json.clone(),
|
||||
options: None,
|
||||
};
|
||||
if command.has_effectively_unbounded_filter() {
|
||||
super::mcp_policy::ensure_dangerous_write(&state, &headers, &req.connection_id, &database, "BulkWrite").await?;
|
||||
} else {
|
||||
super::mcp_policy::ensure_write(&state, &headers, &req.connection_id, &database, "BulkWrite").await?;
|
||||
}
|
||||
ensure_writable(&state.app, &req.connection_id, "BulkWrite").await?;
|
||||
let result = dbx_core::mongo_ops::mongo_bulk_write_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
&database,
|
||||
&req.collection,
|
||||
&req.operations_json,
|
||||
req.options_json.as_deref(),
|
||||
)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn find_one_and_update(
|
||||
State(state): State<Arc<WebState>>,
|
||||
headers: HeaderMap,
|
||||
|
||||
Reference in new issue
Block a user