diff --git a/libs/community/langchain_community/document_loaders/mongodb.py b/libs/community/langchain_community/document_loaders/mongodb.py index 57b4f35217c..b1e06222654 100644 --- a/libs/community/langchain_community/document_loaders/mongodb.py +++ b/libs/community/langchain_community/document_loaders/mongodb.py @@ -77,7 +77,19 @@ class MongodbLoader(BaseLoader): # Extract text content from filtered fields or use the entire document if self.field_names is not None: - fields = {name: doc[name] for name in self.field_names} + fields = {} + for name in self.field_names: + # Split the field names to handle nested fields + keys = name.split(".") + value = doc + for key in keys: + if key in value: + value = value[key] + else: + value = "" + break + fields[name] = value + texts = [str(value) for value in fields.values()] text = " ".join(texts) else: