MongoDB Datatype Mapping
  • 2 Minutes to read
  • Dark
    Light
  • PDF

MongoDB Datatype Mapping

  • Dark
    Light
  • PDF

Article Summary

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.

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:

_idPriceFeaturesUpdated_atUpdated_epoch
313440R4E88{"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
_idSTRING
PriceFLOAT
FeaturesJSON
Updated_atTIMESTAMP
Updated_epochINTEGER

  1. 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
_idSTRING
PriceSTRING
FeaturesJSON
Updated_atTIMESTAMP
Updated_epochINTEGER

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 TypeRivery Type
DoubleFLOAT
StringSTRING
ObjectJSON
ArrayJSON
Binary dataSTRING
UndefinedSTRING
ObjectIdSTRING
BooleanBOOLEAN
DateTIMESTAMP
Regular ExpressionSTRING
DBPointerSTRING
JavaScriptSTRING
SymbolSTRING
JavaScript code with scopeSTRING
32-bit integerINTEGER
TimestampINTEGER
64-bit integerINTEGER
Decimal128FLOAT
Min keySTRING
Max keySTRING

Was this article helpful?

What's Next