MongoDBLoader#

class langchain_mongodb.loaders.MongoDBLoader(
collection: Collection,
*,
filter_criteria: Dict | None = None,
field_names: Sequence[str] | None = None,
metadata_names: Sequence[str] | None = None,
include_db_collection_in_metadata: bool = True,
)[source]#

Document Loaders are classes to load Documents.

Document Loaders are usually used to load a lot of Documents in a single run.

Initializes the MongoDB loader with necessary database connection details and configurations.

Parameters:
  • collection (Collection) – The pymongo collection to fetch documents from.

  • filter_criteria (Optional[Dict]) – MongoDB filter criteria for querying

  • documents. (extract from)

  • field_names (Optional[Sequence[str]]) – List of field names to retrieve

  • documents.

  • metadata_names (Optional[Sequence[str]]) – Additional metadata fields to

  • documents.

  • include_db_collection_in_metadata (bool) – Flag to include database and

  • metadata. (collection names in)

Methods

__init__(collection, *[, filter_criteria, ...])

Initializes the MongoDB loader with necessary database connection details and configurations.

alazy_load()

A lazy loader for Documents.

aload()

Asynchronously loads data into Document objects.

close()

Close the resources used by the MongoDBLoader.

from_connection_string(connection_string, ...)

Creates a MongoDB loader with necessary database connection details and configurations.

lazy_load()

A lazy loader for Documents.

load()

Load data into Document objects.

load_and_split([text_splitter])

Load Documents and split into chunks.

__init__(
collection: Collection,
*,
filter_criteria: Dict | None = None,
field_names: Sequence[str] | None = None,
metadata_names: Sequence[str] | None = None,
include_db_collection_in_metadata: bool = True,
) None[source]#

Initializes the MongoDB loader with necessary database connection details and configurations.

Parameters:
  • collection (Collection) – The pymongo collection to fetch documents from.

  • filter_criteria (Optional[Dict]) – MongoDB filter criteria for querying

  • documents. (extract from)

  • field_names (Optional[Sequence[str]]) – List of field names to retrieve

  • documents.

  • metadata_names (Optional[Sequence[str]]) – Additional metadata fields to

  • documents.

  • include_db_collection_in_metadata (bool) – Flag to include database and

  • metadata. (collection names in)

Return type:

None

async alazy_load() AsyncIterator[Document]#

A lazy loader for Documents.

Return type:

AsyncIterator[Document]

async aload() List[Document][source]#

Asynchronously loads data into Document objects.

Return type:

List[Document]

close() None[source]#

Close the resources used by the MongoDBLoader.

Return type:

None

classmethod from_connection_string(
connection_string: str,
db_name: str,
collection_name: str,
*,
filter_criteria: Dict | None = None,
field_names: Sequence[str] | None = None,
metadata_names: Sequence[str] | None = None,
include_db_collection_in_metadata: bool = True,
) MongoDBLoader[source]#

Creates a MongoDB loader with necessary database connection details and configurations.

Parameters:
  • connection_string (str) – MongoDB connection URI.

  • db_name (str) – Name of the database to connect to.

  • collection_name (str) – Name of the collection to fetch documents from.

  • filter_criteria (Optional[Dict]) – MongoDB filter criteria for querying

  • documents. (extract from)

  • field_names (Optional[Sequence[str]]) – List of field names to retrieve

  • documents.

  • metadata_names (Optional[Sequence[str]]) – Additional metadata fields to

  • documents.

  • include_db_collection_in_metadata (bool) – Flag to include database and

  • metadata. (collection names in)

Return type:

MongoDBLoader

lazy_load() Iterator[Document]#

A lazy loader for Documents.

Return type:

Iterator[Document]

load() List[Document][source]#

Load data into Document objects.

Return type:

List[Document]

load_and_split(
text_splitter: TextSplitter | None = None,
) list[Document]#

Load Documents and split into chunks. Chunks are returned as Documents.

Do not override this method. It should be considered to be deprecated!

Parameters:

text_splitter (Optional[TextSplitter]) – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

Returns:

List of Documents.

Return type:

list[Document]