API version: 0.3.0

---

# String

`string` holds text.

| Value           | Example    |
| --------------- | ---------- |
| any JSON string | `"Berlin"` |

## Settings

| Setting     | Meaning                                                                                                                                                                                                |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `maxLength` | The maximum number of characters, checked on every write. It is not part of the mappings of the databases. Optional, no limit by default.                                                              |
| `enum`      | The allowed values, a non-empty list of distinct strings, e.g. `["draft", "published"]`. Values are compared exactly, also by case. Optional, every string is allowed by default. See [enums](#enums). |

The [settings of every property](/reference/schemas.md#properties) apply as well. A
[raw Elasticsearch](/reference/indices/raw-indices/elasticsearch.md) or [raw Neo4j](/reference/indices/raw-indices/neo4j.md)
index can replace the generic mapping.

## Storage

| Database      | Stored as                                                                                                                   | Notes                                                                                                                                                                            |
| ------------- | --------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Neo4j         | native `STRING`                                                                                                             | (default up to 1024 characters)                                                                                                                                                  |
| MongoDB       | `string`                                                                                                                    | (default above 1024 characters), shorter strings with `"storage": "document"` or the [placement role](/reference/schemas/placement.md#placement-roles) `scalar` moved to MongoDB |
| Elasticsearch | `text` with a `keyword` sub-field, `keyword` for enums (the mapping depends on the [index](/reference/indices/fulltext.md)) | search copy, see below                                                                                                                                                           |

The [search copy](/reference/databases/elasticsearch.md) is written unless the property or the type sets `"search": false`.
Where a property is stored is explained in [placement](/reference/schemas/placement.md).

## Enums

A string with `enum` only accepts the listed values, on every write and in lists
(`"items": {"type": "string", "enum": [...]}`). Use it for values which are known when the schema is written, e.g. a
status; for open sets of values, e.g. tags, use a plain string with an `exact` index instead. MongoDB validates the
values of nested enums as well, and the search copy maps enums as `keyword`, as their values are identifiers, not text.

Changing the list does not change existing elements: an element keeps a value which was removed from the list, until
the property is written again. Writing the old value is rejected.

```json
{
  "type": "string",
  "enum": [
    "draft",
    "published",
    "archived"
  ],
  "index": "exact"
}
```

## Indices

`exact` and `fulltext`, also both together, see [indices](/reference/indices.md). Nested properties can be indexed as well,
see [nested properties](/reference/indices.md#nested-properties).

## Limits

Without `maxLength` the length is only limited by the request size and the databases. Strings of more than 1024
characters are stored in MongoDB unless the property sets a `storage`, as long strings slow down Neo4j. The `keyword`
sub-field of Elasticsearch ignores strings of more than 256 characters, they are still found by the `text` field.

## Example

Schema:

```json
{
  "type": "string",
  "maxLength": 64,
  "index": [
    "exact",
    "fulltext"
  ]
}
```

Input and output:

```json
{
  "data": {
    "value": "Berlin"
  }
}
```

---

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

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

Previous: [Number](/reference/schemas/types/number.md)

Next: [Datetime](/reference/schemas/types/datetime.md)
