feat(mongo): preserve BSON types when cloning and saving documents

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-08-10 23:02:37 +08:00
1 parent cc7112b240
commit a5ce8510e7
12 files changed
+239 -36

No files matched your search

+22 -9
View File
@@ -87,6 +87,7 @@ pub struct DocumentInsertRequest {
pub collection: String,
pub doc_json: String,
pub routing: Option<String>,
pub preserve_bson_types: Option<bool>,
}
#[derive(Deserialize)]
@@ -222,15 +223,27 @@ pub async fn insert_document(
Json(req): Json<DocumentInsertRequest>,
) -> Result<Json<String>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Insert").await?;
let result = dbx_core::document_ops::insert_document_core(
&state.app,
&req.connection_id,
&req.database,
&req.collection,
&req.doc_json,
req.routing.as_deref(),
)
.await
let result = if req.preserve_bson_types.unwrap_or(false) {
dbx_core::document_ops::insert_document_preserving_bson_types_core(
&state.app,
&req.connection_id,
&req.database,
&req.collection,
&req.doc_json,
req.routing.as_deref(),
)
.await
} else {
dbx_core::document_ops::insert_document_core(
&state.app,
&req.connection_id,
&req.database,
&req.collection,
&req.doc_json,
req.routing.as_deref(),
)
.await
}
.map_err(AppError::from)?;
Ok(Json(result))
}