Default mapping of columns with inconsistent native data types
- Last Updated: March 19, 2021
- 1 minute read
- DataDirect Connectors
- JDBC
- MongoDB 6.1
- Documentation
Due to the flexibility of the MongoDB schema data model, your native data sources may not enforce consistent data types. To ensure data integrity when mapping to a relational model, the driver describes columns with inconsistent native data types as a single SQL data type. The driver determines which SQL type to use based on the combination of native types detected when sampling data. The following table lists combinations of MongoDB data types and their default mapping for JDBC.
Note: In some cases, a value with a specific
native type can be concealed or obscured because the driver describes a field with
inconsistent native types as a column with a single SQL type. The
CAST_TO_NATIVE function escape allows users to send a value as it
is defined in the MongoDB database, rather than how it is described in the relational
model of the data. Currently, CAST_TO_NATIVE can only be used with the
ObjectID type in SELECT statement filters and literal
INSERT values. See "CAST_TO_NATIVE Function Escape" for
details.| MongoDB Data Types | JDBC Data Type |
|---|---|
| BIGINT and INTEGER | BIGINT (-5) |
| DOUBLE and INTEGER | DOUBLE (8) |
| All other combinations | VARCHAR (12) or LONGVARCHAR (-1)1 |
1 When the driver discovers a column with 4000
characters or less, the column is mapped as VARCHAR and the
precision is 4000 characters. When the driver discovers a column
with more than 4000 characters, the column is mapped as LONGVARCHAR
and precision is 16 MB.