All connectors

Database

MongoDB

MongoDB Connector

Index the collections of a MongoDB database, sub-documents flattened into readable field paths.

Prerequisites

  • A MongoDB database you can read, version 4.4 or later
  • A user with the `read` role on that database
  • A connection string, or the host, port and database name

Data ingested

When you connect MongoDB, the following content becomes searchable. Every answer that uses it cites it.

ContentWhat is kept
CollectionsEvery collection of the database, one document per collection. System collections are skipped
DocumentsUp to 500 documents per collection, each rendered as a flat field list
Sub-documentsFlattened into dotted paths: `fournisseur.nom`, `adresse.ville`

Setup

Configuration happens in the dashboard, under Integrations. No API call is needed for a normal setup.

1

Create a read-only user

`db.createUser({user: 'qm_reader', pwd: '...', roles: [{role: 'read', db: 'mydb'}]})`. The `read` role is enough: the connector never writes.

2

Enter the connection

Integrations → Add source → MongoDB: the connection string in the **URL** field, or host, port (27017 by default) and database.

3

Set the secret

The password, unless the connection string already carries it. Add `?authSource=admin` when the user is defined on the `admin` database.

4

Connect and sync

**Test** lists the collections without indexing; **Sync** reads the documents and indexes them.

Where the credential goes
The password goes in the **Secret** field, or inside the connection string given in the **URL** field. Either way it is stored server-side and never returned by the API.

Configuration options

FieldDescriptionRequired
URL or DSNFull `mongodb://user:password@host:port/database`. Takes precedence over the separate fieldsNo
HostDatabase host. Defaults to `127.0.0.1`No
PortDatabase port. Defaults to `27017`No
DatabaseName of the database to indexYes
UserUser used to connectYes
SecretPassword of that userNo
SchemaNot used by MongoDB: collections are already scoped to the databaseNo

Best practices

  • •MongoDB documents are heterogeneous: the connector unions the fields of every document read, so a field missing from some documents still appears as a column.
  • •Index a read replica or a secondary rather than the primary when the collection is large: a sync reads up to 500 documents per collection.
  • •System collections (`system.*`) are skipped automatically. There is nothing to exclude by hand.

Troubleshooting

`Authentication failed`

The user is often defined on the `admin` database: add `?authSource=admin` to the connection string, or use a user created on the target database.

`config.database est requis`

The **Database** field is empty. MongoDB cannot list collections without a database name.

An empty collection is indexed as an empty document

A collection with no document yields no readable content and is reported as empty rather than silently skipped.

Connection timeout

The server is reachable but the IP is not in `bindIp`. Check `net.bindIp` in `mongod.conf`, and open the port in the firewall.

Next steps

Once the source is connected and indexed, ask a question from the chat and check that the answer cites this source. A source that never appears in a citation is usually a source with nothing indexed: see Troubleshooting above.