> ## Documentation Index
> Fetch the complete documentation index at: https://forest-chore-open-api.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Mongoid datasource

> Connect Forest to MongoDB using Mongoid models with flexible nested document handling

The Mongoid datasource imports collections from a Mongoid instance into Forest, with configurable strategies for handling deeply nested embedded documents.

<Warning>
  Mongoid datasource is only available for Ruby. For Node.js, check the [Mongoose datasource](/get-started/connect/data-sources/mongoose) or [MongoDB datasource](/get-started/connect/data-sources/mongodb).
</Warning>

## Basic usage

```ruby theme={null}
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.

```ruby theme={null}
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.

```ruby theme={null}
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.

```ruby theme={null}
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`](https://github.com/ForestAdmin/agent-ruby/tree/main/packages/forest_admin_datasource_mongoid).
