Skip to content

Commit 3cd0820

Browse files
author
Rafael Odon
committed
Preventing authorized collections listing issues in other parts of the code.
1 parent bd2a609 commit 3cd0820

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

libs/langchain-mongodb/langchain_mongodb/cache.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def __init__(
5252
self.__database_name = database_name
5353
self.__collection_name = collection_name
5454

55-
if self.__collection_name not in self.database.list_collection_names():
55+
if self.__collection_name not in self.database.list_collection_names(
56+
authorizedCollections=True
57+
):
5658
self.database.create_collection(self.__collection_name)
5759
# Create an index on key and llm_string
5860
self.collection.create_index([self.PROMPT, self.LLM])

libs/langchain-mongodb/langchain_mongodb/graphrag/graph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def __init__(
142142
driver=DRIVER_METADATA,
143143
)
144144
db = client[database_name]
145-
if collection_name not in db.list_collection_names():
145+
if collection_name not in db.list_collection_names(
146+
authorizedCollections=True
147+
):
146148
validator = {"$jsonSchema": self._schema} if validate else None
147149
collection = client[database_name].create_collection(
148150
collection_name,

libs/langchain-mongodb/langchain_mongodb/index.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def create_vector_search_index(
6060
"""
6161
logger.info("Creating Search Index %s on %s", index_name, collection.name)
6262

63-
if collection.name not in collection.database.list_collection_names():
63+
if collection.name not in collection.database.list_collection_names(
64+
authorizedCollections=True
65+
):
6466
collection.database.create_collection(collection.name)
6567

6668
result = collection.create_search_index(
@@ -219,7 +221,9 @@ def create_fulltext_search_index(
219221
"""
220222
logger.info("Creating Search Index %s on %s", index_name, collection.name)
221223

222-
if collection.name not in collection.database.list_collection_names():
224+
if collection.name not in collection.database.list_collection_names(
225+
authorizedCollections=True
226+
):
223227
collection.database.create_collection(collection.name)
224228

225229
if isinstance(field, str):

libs/langgraph-store-mongodb/langgraph/store/mongodb/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ def from_conn_string(
251251
driver=DRIVER_METADATA,
252252
)
253253
db = client[db_name]
254-
if collection_name not in db.list_collection_names():
254+
if collection_name not in db.list_collection_names(
255+
authorizedCollections=True
256+
):
255257
db.create_collection(collection_name)
256258
collection = client[db_name][collection_name]
257259

0 commit comments

Comments
 (0)