- 2 Minutes to read
- Print
- DarkLight
- PDF
MongoDB Datatype Mapping
- 2 Minutes to read
- Print
- DarkLight
- PDF
This article explains the MongoDB mapping process.
Overview
MongoDB is a NoSQL database with no fixed columns or tables. Simply put, it has collections and dynamic schemas that are similar to tables. MongoDB is a document-oriented database that uses JSON documents as its primary storage format.
Mapping Process
First-level fields are mapped to columns in your destination based on the last 100 documents. We translate the first-level field to its own type if it is a basic data type. We transfer it to a JSON type without unpacking if it's a complex data type like an array or JSON data.
Nested JSON objects are not immediately unpacked into separate tables in the destination. Any nested JSON objects in the destination are preserved in their original state, allowing you to use JSON processing functions.
Please be aware that this varies depending on the specific Target you select to work with. To determine if this occurs, please refer to the "Datatype Mapping" documentation for your chosen Target in our knowledgebase.
Consider the following JSON:
{
"_id": "313440R4E",
"Price": 88,
"Features": {
"Top_category": "Movies",
"Category": "Science Fiction",
"Sub_category": "Classic",
"Name": "Back to the Future",
"Category_id": "1985",
"Subject": "Roads, where we going we don't need roads"
},
"Updated_at": "2015-10-21T00:00:00.000Z",
"Updated_epoch": 1449180000
}
When we load it into your destination, it is converted to the following table:
_id | Price | Features | Updated_at | Updated_epoch |
---|---|---|---|---|
313440R4E | 88 | {"Top_category": "Movies", "Category": "Science Fiction", "Sub_category": "Classic", "Name": "Back to the Future", "Category_id": "1985", "Subject": "Roads, where we going we don't need roads"} | '2015-10-21T00:00:00.000Z' | 1449180000 |
Conversion of Data Types
We convert JSON to Rivery data types as we extract your data.
Here are some datatype conversion examples:
1. Consider the JSON below:
{
"_id": "313440R4E",
"Price": 88.01,
"Features": {
"Top_category": "Movies",
"Category": "Science Fiction",
"Sub_category": "Classic",
"Name": "Back to the Future",
"Category_id": "1985",
"Subject": "Roads, where we going we don't need roads"
},
"Updated_at": "2015-10-21T00:00:00.000Z",
"Updated_epoch": 1449180000
}
Following the conversion:
Type | |
---|---|
_id | STRING |
Price | FLOAT |
Features | JSON |
Updated_at | TIMESTAMP |
Updated_epoch | INTEGER |
2. Consider the JSON below:
{
"_id": "618440R4F",
"Price": "154.23 EUR",
"Features": {
"Top_category": "Movies",
"Category": "Action",
"Sub_category": "Classic",
"Name": "Top Gun",
"Category_id": 1986,
"Subject": "Maverick, you just did an incredibly brave thing"
},
"Updated_at": "2015-10-22T00:00:00.000Z",
"Updated_epoch": 1449180000
}
Following the conversion:
Type | |
---|---|
_id | STRING |
Price | STRING |
Features | JSON |
Updated_at | TIMESTAMP |
Updated_epoch | INTEGER |
Type Mapping
While extracting your data, we match MongoDB data types to Rivery data types. If a data type isn't supported, we will automatically map it as a String type.
The mapping of MongoDB data types to Rivery-compatible types is shown in the table below:
MongoDB Type | Rivery Type |
---|---|
Double | FLOAT |
String | STRING |
Object | JSON |
Array | JSON |
Binary data | STRING |
Undefined | STRING |
ObjectId | STRING |
Boolean | BOOLEAN |
Date | TIMESTAMP |
Regular Expression | STRING |
DBPointer | STRING |
JavaScript | STRING |
Symbol | STRING |
JavaScript code with scope | STRING |
32-bit integer | INTEGER |
Timestamp | INTEGER |
64-bit integer | INTEGER |
Decimal128 | FLOAT |
Min key | STRING |
Max key | STRING |