From 3bdcfa6ea8374865dfabb7143b06f8065db0a60e Mon Sep 17 00:00:00 2001 From: Ashish Bhatia <ashishb@ashishb.net> Date: Tue, 9 Apr 2024 11:34:22 -0700 Subject: [PATCH] Improve efficiency of MongoDB reader (#12664) --- .../llama_index/readers/mongodb/base.py | 6 +++++- .../readers/llama-index-readers-mongodb/pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/llama-index-integrations/readers/llama-index-readers-mongodb/llama_index/readers/mongodb/base.py b/llama-index-integrations/readers/llama-index-readers-mongodb/llama_index/readers/mongodb/base.py index edd19163a9..db27a62e2a 100644 --- a/llama-index-integrations/readers/llama-index-readers-mongodb/llama_index/readers/mongodb/base.py +++ b/llama-index-integrations/readers/llama-index-readers-mongodb/llama_index/readers/mongodb/base.py @@ -78,7 +78,11 @@ class SimpleMongoReader(BaseReader): """ db = self.client[db_name] - cursor = db[collection_name].find(filter=query_dict or {}, limit=max_docs) + cursor = db[collection_name].find( + filter=query_dict or {}, + limit=max_docs, + projection={name: 1 for name in field_names + (metadata_names or [])}, + ) for item in cursor: try: diff --git a/llama-index-integrations/readers/llama-index-readers-mongodb/pyproject.toml b/llama-index-integrations/readers/llama-index-readers-mongodb/pyproject.toml index 5b8e005c95..3c8cfa1ed2 100644 --- a/llama-index-integrations/readers/llama-index-readers-mongodb/pyproject.toml +++ b/llama-index-integrations/readers/llama-index-readers-mongodb/pyproject.toml @@ -28,7 +28,7 @@ license = "MIT" maintainers = ["jerryjliu"] name = "llama-index-readers-mongodb" readme = "README.md" -version = "0.1.3" +version = "0.1.4" [tool.poetry.dependencies] python = ">=3.8.1,<4.0" -- GitLab