Skip to main content
The MongoDB datasource connects directly to MongoDB without requiring Mongoose or another ORM. It automatically introspects your collections by sampling documents to infer the schema.
MongoDB datasource is only available for Node.js. For Ruby, check the Mongoid datasource.

Basic usage

Schema introspection

Since MongoDB lacks a predefined schema, the back-end samples documents from each collection during startup to infer the structure. You can control this behavior:
Setting sample sizes too high may slow back-end startup times.

Filtering collections

Exclude specific collections from Forest:

Flattening nested data

MongoDB stores nested BSON documents. Configure flattening to convert nested structures into columns or separate collections:

Data navigation

When customizing your back-end, navigate paths using these separators:
  • Nested fields: Use @@@ to access nested properties
  • Related data: Use : to navigate relationships
Example: address:city@@@name accesses the name field within city within the address relation.

Source code

This connector is open source. Browse the code or contribute on GitHub: @forestadmin/datasource-mongo.