fix(mongodb): support legacy Agent findOne queries

Closes #5300
This commit is contained in:
t8y2 committed 2026-08-04 13:09:33 +08:00
1 parent 343ef6fa84
commit 2e57ac8bc0
9 files changed
+202 -7

No files matched your search

+10 -1
View File
@@ -1272,6 +1272,7 @@ pub enum MongoAgentMethod {
ListDatabases,
ListCollections,
FindDocuments,
FindOne,
FindDocumentsExtendedJson,
CountDocuments,
ServerVersion,
@@ -1287,10 +1288,11 @@ pub enum MongoAgentMethod {
}
impl MongoAgentMethod {
pub const ALL: [Self; 15] = [
pub const ALL: [Self; 16] = [
Self::ListDatabases,
Self::ListCollections,
Self::FindDocuments,
Self::FindOne,
Self::FindDocumentsExtendedJson,
Self::CountDocuments,
Self::ServerVersion,
@@ -1310,6 +1312,7 @@ impl MongoAgentMethod {
Self::ListDatabases => "list_databases",
Self::ListCollections => "list_collections",
Self::FindDocuments => "find_documents",
Self::FindOne => "find_one",
Self::FindDocumentsExtendedJson => "find_documents_extended_json",
Self::CountDocuments => "count_documents",
Self::ServerVersion => "server_version",
@@ -2464,6 +2467,10 @@ impl AgentDriverClient {
self.call_mongo_method(MongoAgentMethod::FindDocuments, params).await
}
pub async fn mongo_find_one<T: DeserializeOwned + Send + 'static>(&mut self, params: Value) -> Result<T, String> {
self.call_mongo_method(MongoAgentMethod::FindOne, 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,
@@ -4314,6 +4321,7 @@ for line in sys.stdin:
assert_eq!(MongoAgentMethod::ListDatabases.as_str(), "list_databases");
assert_eq!(MongoAgentMethod::ListCollections.as_str(), "list_collections");
assert_eq!(MongoAgentMethod::FindDocuments.as_str(), "find_documents");
assert_eq!(MongoAgentMethod::FindOne.as_str(), "find_one");
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");
@@ -4381,6 +4389,7 @@ for line in sys.stdin:
let _mongo_list_collections = AgentDriverClient::mongo_list_collections::<serde_json::Value>;
let _mongo_list_collection_specs = AgentDriverClient::mongo_list_collection_specs::<serde_json::Value>;
let _mongo_find_documents = AgentDriverClient::mongo_find_documents::<serde_json::Value>;
let _mongo_find_one = AgentDriverClient::mongo_find_one::<serde_json::Value>;
let _mongo_find_documents_extended_json =
AgentDriverClient::mongo_find_documents_extended_json::<serde_json::Value>;
let _mongo_server_version = AgentDriverClient::mongo_server_version::<serde_json::Value>;
+12 -2
View File
@@ -170,8 +170,18 @@ pub async fn mongo_find_one_core(
PoolKind::MongoDb(client) => {
mongo_driver::find_one(client, database, collection, filter, projection, options).await
}
// The legacy agent only exposes paginated find, which also performs a count.
PoolKind::Agent(_) => Err("MongoDB legacy agent does not support the bounded findOne path".to_string()),
PoolKind::Agent(client) => {
let mut client = client.lock().await;
client
.mongo_find_one(serde_json::json!({
"database": database,
"collection": collection,
"filter": filter,
"projection": projection,
"options": options,
}))
.await
}
_ => Err("Not a MongoDB connection".to_string()),
}
}