fix(mongodb): support legacy aggregate commands

Closes #5575
This commit is contained in:
t8y2 committed 2026-08-08 20:30:20 +08:00
1 parent d38e58b136
commit f10642e29a
9 files changed
+399 -6

No files matched your search

@@ -39,6 +39,6 @@
"disconnect",
"shutdown"
],
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "find_documents_extended_json", "count_documents", "server_version", "create_index", "drop_indexes", "drop_collection", "drop_database", "insert_document", "update_document", "update_documents", "delete_document", "delete_documents"],
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "drop_indexes", "drop_collection", "drop_database", "insert_document", "update_document", "update_documents", "delete_document", "delete_documents"],
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"]
}
@@ -43,7 +43,7 @@
"disconnect",
"shutdown"
],
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "find_documents_extended_json", "count_documents", "server_version", "create_index", "drop_indexes", "drop_collection", "drop_database", "insert_document", "update_document", "update_documents", "delete_document", "delete_documents"],
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "drop_indexes", "drop_collection", "drop_database", "insert_document", "update_document", "update_documents", "delete_document", "delete_documents"],
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"],
"sessionField": "agentSessionId",
"cursorSessionField": "sessionId"
+12 -1
View File
@@ -1274,6 +1274,7 @@ pub enum MongoAgentMethod {
FindDocuments,
FindOne,
ExplainFind,
AggregateDocuments,
FindDocumentsExtendedJson,
CountDocuments,
ServerVersion,
@@ -1289,12 +1290,13 @@ pub enum MongoAgentMethod {
}
impl MongoAgentMethod {
pub const ALL: [Self; 17] = [
pub const ALL: [Self; 18] = [
Self::ListDatabases,
Self::ListCollections,
Self::FindDocuments,
Self::FindOne,
Self::ExplainFind,
Self::AggregateDocuments,
Self::FindDocumentsExtendedJson,
Self::CountDocuments,
Self::ServerVersion,
@@ -1316,6 +1318,7 @@ impl MongoAgentMethod {
Self::FindDocuments => "find_documents",
Self::FindOne => "find_one",
Self::ExplainFind => "explain_find",
Self::AggregateDocuments => "aggregate_documents",
Self::FindDocumentsExtendedJson => "find_documents_extended_json",
Self::CountDocuments => "count_documents",
Self::ServerVersion => "server_version",
@@ -2481,6 +2484,13 @@ impl AgentDriverClient {
self.call_mongo_method(MongoAgentMethod::ExplainFind, params).await
}
pub async fn mongo_aggregate_documents<T: DeserializeOwned + Send + 'static>(
&mut self,
params: Value,
) -> Result<T, String> {
self.call_mongo_method(MongoAgentMethod::AggregateDocuments, params).await
}
/// Calls the Mongo agent read method that returns MongoDB relaxed Extended JSON.
pub async fn mongo_find_documents_extended_json<T: DeserializeOwned + Send + 'static>(
&mut self,
@@ -4333,6 +4343,7 @@ for line in sys.stdin:
assert_eq!(MongoAgentMethod::FindDocuments.as_str(), "find_documents");
assert_eq!(MongoAgentMethod::FindOne.as_str(), "find_one");
assert_eq!(MongoAgentMethod::ExplainFind.as_str(), "explain_find");
assert_eq!(MongoAgentMethod::AggregateDocuments.as_str(), "aggregate_documents");
assert_eq!(MongoAgentMethod::FindDocumentsExtendedJson.as_str(), "find_documents_extended_json");
assert_eq!(MongoAgentMethod::CountDocuments.as_str(), "count_documents");
assert_eq!(MongoAgentMethod::ServerVersion.as_str(), "server_version");
+18 -1
View File
@@ -386,7 +386,24 @@ pub async fn mongo_aggregate_documents_core(
PoolKind::MongoDb(client) => {
mongo_driver::aggregate_documents(client, database, collection, pipeline_json, max_rows, options_json).await
}
PoolKind::Agent(_) => Err("MongoDB legacy agent does not support aggregate".to_string()),
PoolKind::Agent(client) => {
let mut client = client.lock().await;
let params = serde_json::json!({
"database": database,
"collection": collection,
"pipeline": pipeline_json,
"limit": max_rows.unwrap_or(100),
"options": options_json,
});
match client.mongo_aggregate_documents(params).await {
Ok(result) => Ok(result),
Err(error) if is_unknown_agent_method_error(&error, "aggregate_documents") => Err(
"MongoDB Legacy Agent does not support aggregate; upgrade or reinstall the MongoDB Legacy driver"
.to_string(),
),
Err(error) => Err(error),
}
}
_ => Err("Not a MongoDB connection".to_string()),
}
}