feat(mongodb): support db.collection.renameCollection()
This commit is contained in:
1 parent
392138f59a
commit
2db28fc236
16 files changed
+239
-17
No files matched your search
@@ -95,7 +95,23 @@ pub async fn mongo_rename_collection_core(
|
||||
let pool = state.pool_handle(connection_id).await.ok_or("Not found")?;
|
||||
match &pool {
|
||||
PoolKind::MongoDb(client) => mongo_driver::rename_collection(client, database, collection, new_name).await,
|
||||
PoolKind::Agent(_) => Err("MongoDB legacy agent does not support rename collection".to_string()),
|
||||
PoolKind::Agent(client) => {
|
||||
let mut client = client.lock().await;
|
||||
if !client.supports_capability(AgentCapability::MongoRenameCollection) {
|
||||
return Err(
|
||||
"MongoDB Legacy Agent does not support renameCollection; upgrade or reinstall the MongoDB Legacy driver"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
let _: serde_json::Value = client
|
||||
.mongo_rename_collection(serde_json::json!({
|
||||
"database": database,
|
||||
"collection": collection,
|
||||
"new_name": new_name,
|
||||
}))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
_ => Err("Not a MongoDB connection".to_string()),
|
||||
}
|
||||
}
|
||||
@@ -1200,6 +1216,10 @@ pub async fn execute_mongo_command_core(
|
||||
mongo_drop_collection_core(state, connection_id, database, collection).await?;
|
||||
Ok(affected_query_result(1))
|
||||
}
|
||||
MongoCommand::RenameCollection { collection, new_name } => {
|
||||
mongo_rename_collection_core(state, connection_id, database, collection, new_name).await?;
|
||||
Ok(scalar_query_result("renamed", Value::String(format!("{collection} -> {new_name}"))))
|
||||
}
|
||||
MongoCommand::FindOneAndUpdate { collection, filter, update, options } => {
|
||||
let result = mongo_find_one_and_update_core(
|
||||
state,
|
||||
|
||||
Reference in new issue
Block a user