# Supported data types (MongoDB)

## Writing: .NET to MongoDB

| .NET value | Stored as |
|---|---|
| `string`, `char` | string |
| a plain `enum` | refused (ARX1007): write `(int)value` or `value.ToString()`, or use a selection set |
| `int`, `short`, `byte` | 32-bit integer |
| `long`, `uint` | 64-bit integer |
| `decimal` | Decimal128 (exact) |
| `double`, `float` | double (NaN and infinity allowed) |
| `bool` | boolean |
| `Guid` | binary subtype 4 (UUID) |
| `byte[]`, `ArxBytea` | binary |
| `ArxJsonB` | an embedded document or array (its JSON parsed) |
| an array or a list | an array of the values above |
| `ArxSelectionSetValue` | its code, or an array of codes |
| `ArxEntityReference` | the referenced id, as the referenced collection stores it (an ObjectId for a generated string id) |
| `null` | null |

## Dates and times

| .NET value | Stored as |
|---|---|
| `DateTime` (UTC) | a BSON date, to the millisecond: finer ticks are dropped |
| `DateTime` (Local) | converted to UTC |
| `DateTime` (Unspecified) | taken as UTC |
| `DateTimeOffset` | its UTC instant (the offset isn't kept) |
| `DateOnly` | midnight UTC of that day |
| `TimeOnly`, `TimeSpan` | text (`09:30:00.0000000`, `1.02:03:04`) |
| `default(DateTime)`, `default(DateTimeOffset)`, `default(DateOnly)` | refused (ARX1013): they mean "not set" |

## Reading: MongoDB to .NET

| Stored as | Read back as |
|---|---|
| string | `string` |
| 32-bit integer | `int` |
| 64-bit integer | `long` |
| double | `double` |
| Decimal128 | `decimal` (ARX4001 past .NET's range) |
| boolean | `bool` |
| date | `DateTime`, UTC (a `DateOnly` is stored as midnight UTC: read it with `GetAttributeValue<DateOnly>`, which converts a midnight `DateTime` from 0.1.0-preview.5, or preload the field) |
| ObjectId | `string` (24 hexadecimal characters) |
| binary subtype 4 | `Guid` |
| other binary | `byte[]` |
| embedded document | `ArxJsonB` |
| array of one kind of value | a typed array (`string[]`, `int[]`, …); any other array as `ArxJsonB` |
| a declared lookup | `ArxEntityReference` |
| a preloaded field | the preloaded type (`DateOnly` from a date, `TimeOnly` from text, …) |
