Skip to main content
The Mongoid datasource imports collections from a Mongoid instance into Forest, with configurable strategies for handling deeply nested embedded documents.
Mongoid datasource is only available for Ruby. For Node.js, check the Mongoose datasource or MongoDB datasource.

Basic usage

require 'forest_admin_datasource_mongoid'

datasource = ForestAdminDatasourceMongoid::Datasource.new(
  options: {
    flatten_mode: 'auto',
  }
)

Flatten modes

The Mongoid datasource provides three modes for handling embedded documents:

flatten_mode: 'auto'

Embedded documents (embeds_one, embeds_many) are automatically converted into separate Forest collections.
datasource = ForestAdminDatasourceMongoid::Datasource.new(
  options: {
    flatten_mode: 'auto',
  }
)

flatten_mode: 'manual'

You control which virtual collections are created and which fields are moved to the root level.
datasource = ForestAdminDatasourceMongoid::Datasource.new(
  options: {
    flatten_mode: 'manual',
    # Configure which paths become collections vs fields
    # Contact Forest support for manual mode configuration details
  }
)

flatten_mode: 'none'

Mongoid models are displayed as-is, with embedded objects appearing as raw JSON.
datasource = ForestAdminDatasourceMongoid::Datasource.new(
  options: {
    flatten_mode: 'none',
  }
)

Data navigation

When working with nested or related data, use specific 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: forest_admin_datasource_mongoid.