fix(mongodb): wrap list() return in outer list to match interface contract (#5729)

This commit is contained in:
Hrushikesh Yadav
2026-06-22 11:54:16 +05:30
committed by GitHub
parent 513b56159f
commit ce0531a13e
2 changed files with 19 additions and 15 deletions
+2 -2
View File
@@ -382,10 +382,10 @@ class MongoDB(VectorStoreBase):
cursor = self.collection.find(query).limit(top_k) cursor = self.collection.find(query).limit(top_k)
results = [OutputData(id=str(doc["_id"]), score=None, payload=doc.get("payload")) for doc in cursor] results = [OutputData(id=str(doc["_id"]), score=None, payload=doc.get("payload")) for doc in cursor]
logger.info(f"Retrieved {len(results)} documents from collection '{self.collection_name}'.") logger.info(f"Retrieved {len(results)} documents from collection '{self.collection_name}'.")
return results return [results]
except PyMongoError as e: except PyMongoError as e:
logger.error(f"Error listing documents: {e}") logger.error(f"Error listing documents: {e}")
return [] return [[]]
def reset(self): def reset(self):
"""Reset the index by deleting and recreating it.""" """Reset the index by deleting and recreating it."""
+11 -7
View File
@@ -322,9 +322,10 @@ def test_list(mongo_vector_fixture):
mock_collection.find.assert_called_once_with({}) mock_collection.find.assert_called_once_with({})
mock_cursor.limit.assert_called_once_with(2) mock_cursor.limit.assert_called_once_with(2)
assert len(results) == 2 assert len(results) == 1
assert results[0].id == "id1" assert len(results[0]) == 2
assert results[0].payload == {"key": "value1"} assert results[0][0].id == "id1"
assert results[0][0].payload == {"key": "value1"}
def test_list_with_filters(mongo_vector_fixture): def test_list_with_filters(mongo_vector_fixture):
@@ -351,9 +352,10 @@ def test_list_with_filters(mongo_vector_fixture):
mock_cursor.limit.assert_called_once_with(2) mock_cursor.limit.assert_called_once_with(2)
assert len(results) == 1 assert len(results) == 1
assert results[0].payload["user_id"] == "alice" assert len(results[0]) == 1
assert results[0].payload["agent_id"] == "agent1" assert results[0][0].payload["user_id"] == "alice"
assert results[0].payload["run_id"] == "run1" assert results[0][0].payload["agent_id"] == "agent1"
assert results[0][0].payload["run_id"] == "run1"
def test_list_with_single_filter(mongo_vector_fixture): def test_list_with_single_filter(mongo_vector_fixture):
@@ -378,7 +380,8 @@ def test_list_with_single_filter(mongo_vector_fixture):
mock_cursor.limit.assert_called_once_with(2) mock_cursor.limit.assert_called_once_with(2)
assert len(results) == 1 assert len(results) == 1
assert results[0].payload["user_id"] == "alice" assert len(results[0]) == 1
assert results[0][0].payload["user_id"] == "alice"
def test_list_with_no_filters(mongo_vector_fixture): def test_list_with_no_filters(mongo_vector_fixture):
@@ -397,3 +400,4 @@ def test_list_with_no_filters(mongo_vector_fixture):
mock_cursor.limit.assert_called_once_with(2) mock_cursor.limit.assert_called_once_with(2)
assert len(results) == 1 assert len(results) == 1
assert len(results[0]) == 1