API version: 0.3.0

---

# MongoDB

[MongoDB](https://www.mongodb.com) is a primary database. It stores everything which does not fit into the graph: one
document per element, in a collection per type, with the objects, lists, vectors, geo values and long strings of the
element.

## What it stores

| Values                                | Stored as                             |
| ------------------------------------- | ------------------------------------- |
| `object`, `list`                      | embedded documents and arrays, always |
| `vector`                              | array of numbers, by default          |
| geo types                             | GeoJSON objects, by default           |
| `string` of more than 1024 characters | string, by default                    |
| scalar types                          | native values, if placed here         |

Properties which are stored in MongoDB, and all nested properties, are indexed here: `exact` creates an ascending index,
`fulltext` adds the property to the text index of the collection and `geo` creates a `2dsphere` index, see
[nested properties](/reference/indices.md#nested-properties). A migration creates the indices and adds a
`$jsonSchema` validator to the collection, a second line of defense behind the validation of the API.

## Limits

- **16 MB per document**: a document can not be larger than 16 MB. All properties of an element which are stored in
  MongoDB share this limit, writes which exceed it fail. Large data belongs into a [file](/reference/elements/file.md).
- **100 levels of nesting**: documents can be nested at most 100 levels deep. The API does not limit the nesting of
  objects, so this is the effective limit.

## Migrations

Creating the collection and setting the validator are also done when a schema is saved and after a
[backup load](/command/backup-load.md) (the steps `create-collection` and `update-validator`). Building indices can take
long on big collections and stays migration work, as does removing a validator; errors are logged and do not fail the
save. A [migration](/reference/schemas/migrations.md) adds the `$jsonSchema` validator for the properties which are stored
in MongoDB (`object`, `list`, `vector`, geo values and long strings) and everything inside objects and lists (dates
there as RFC 3339 strings), and creates the indices of these properties, including nested ones. The validator is only
applied to documents which are valid already, and `null` is always allowed. Validators which were not created by schemas
are never touched.

## See also

- [MongoDB's limits](https://www.mongodb.com/docs/manual/reference/limits/)
- [MongoDB's type documentation](https://www.mongodb.com/docs/mongodb-shell/reference/data-types/)

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [Neo4j](/reference/databases/neo4j.md)

Next: [Elasticsearch](/reference/databases/elasticsearch.md)
