feat(mongo): preserve BSON types when cloning and saving documents
This commit is contained in:
12 files changed
+239
-36
No files matched your search
@@ -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))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user