Tool

Load MongoDB Data for LlamaIndex

LlamaIndex reader that loads MongoDB documents, concatenating chosen fields into text.

Works with mongodbllamaindexlangchain

71
Spark score
out of 100
Updated 2 days ago
Version 0.14.23
Models

Add to Favorites

Why it matters

Effortlessly ingest and prepare your MongoDB data for use with LlamaIndex. This integration allows you to easily load documents, specifying fields and filters, to power your AI applications.

Outcomes

What it gets done

01

Connect to MongoDB databases and collections.

02

Select and concatenate specific fields from documents.

03

Filter documents using custom query dictionaries.

04

Prepare data for LlamaIndex or LangChain agents.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-reader-readers-mongodb | bash

Overview

LlamaIndex Readers Integration: Mongo

Simple Mongo Reader loads MongoDB documents into LlamaIndex, concatenating selected fields into each document's text, filterable by a query dict and capped by max_docs. Use it when you need MongoDB documents pulled into LlamaIndex text. It requires a reachable MongoDB instance via host/port or a connection URI.

What it does

Simple Mongo Reader loads data from a MongoDB database. It concatenates specified fields from each MongoDB document into a single LlamaIndex document.

When to use - and when NOT to

Use it when you need MongoDB documents pulled into LlamaIndex, with control over which fields get concatenated, how they are filtered, and how many documents load. It connects via a host/port pair or a Mongo connection URI, so it is not usable without an existing, reachable MongoDB instance.

Inputs and outputs

Install with:

pip install llama-index-readers-mongodb

Initialize with connection details, then lazy-load by database and collection:

from llama_index.readers.mongodb import SimpleMongoReader

reader = SimpleMongoReader(
    host="<Mongo Host>",  # Mongo host address
    port=27017,  # Mongo port (default: 27017)
    uri="<Mongo Connection String>",  # Provide the URI if not using host and port
)

documents = reader.lazy_load_data(
    db_name="<Database Name>",  # Name of the database
    collection_name="<Collection Name>",  # Name of the collection
    field_names=[
        "text"
    ],  # Names of the fields to concatenate (default: ["text"])
    separator="",  # Separator between fields (default: "")
    query_dict=None,  # Query to filter documents (default: None)
    max_docs=0,  # Maximum number of documents to load (default: 0)
    metadata_names=None,  # Names of the fields to add to metadata attribute (default: None)
)

lazy_load_data takes a db_name and collection_name, field_names to concatenate (default ["text"]) joined by an optional separator, a query_dict filter, a max_docs cap (default 0, meaning no limit), and metadata_names for fields to carry into document metadata.

Who it's for

Developers building LlamaIndex or LangChain pipelines that need MongoDB documents loaded and concatenated into text, filterable by query and field selection.

Source README

LlamaIndex Readers Integration: Mongo

Overview

Simple Mongo Reader allows loading data from a MongoDB database. It concatenates specified fields from each document into a single document used by LlamaIndex.

Installation

You can install MongoDB Reader via pip:

pip install llama-index-readers-mongodb

Usage

from llama_index.readers.mongodb import SimpleMongoReader

### Initialize SimpleMongoReader
reader = SimpleMongoReader(
    host="<Mongo Host>",  # Mongo host address
    port=27017,  # Mongo port (default: 27017)
    uri="<Mongo Connection String>",  # Provide the URI if not using host and port
)

### Lazy load data from MongoDB
documents = reader.lazy_load_data(
    db_name="<Database Name>",  # Name of the database
    collection_name="<Collection Name>",  # Name of the collection
    field_names=[
        "text"
    ],  # Names of the fields to concatenate (default: ["text"])
    separator="",  # Separator between fields (default: "")
    query_dict=None,  # Query to filter documents (default: None)
    max_docs=0,  # Maximum number of documents to load (default: 0)
    metadata_names=None,  # Names of the fields to add to metadata attribute (default: None)
)

Implementation for MongoDB reader can be found here

This loader is designed to be used as a way to load data into
LlamaIndex and/or subsequently
used as a Tool in a LangChain Agent.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.