Mapping Examples

Basic Mapping Without Nested Documents

Document
{
    "_id" : ObjectId("5716054bee6e764c94fa7ddd"),
    "name" : "MongoDB extractor"
}
Document in Strict Mode
{
    "_id": {
        "$oid" : "5716054bee6e764c94fa7ddd"
    },
    "name": "MongoDB extractor"
}
Mapping
{
    "_id.$oid": "id",
    "name": "name"
}
Output extractors
idname
5716054bee6e764c94fa7dddMongoDB extractor

Defining Primary Key

Document
{
    "_id" : ObjectId("5716054bee6e764c94fa7ddd")
}
Document in Strict Mode
{
    "_id": {
        "$oid" : "5716054bee6e764c94fa7ddd"
    }
}
Mapping
{
    "_id.$oid": {
        "type": "column",
        "mapping": {
            "destination": "id",
            "primaryKey": true
        }
    }
}
Output extractors
id (marked as PK)
5716054bee6e764c94fa7ddd

Mapping with Nested Documents

Document
{
    "_id" : ObjectId("5716054bee6e764c94fa7ddd"),
    "name" : "MongoDB extractor",
    "revisions" : [
        {
            "id" : "1c6262e",
            "desc" : "First version"
        },
        {
            "id" : "68fc980",
            "desc" : "Second version"
        }
    ],
    "status" : {
        "isActive" : 1,
        "isDeleted" : 0
    }
}
Document in Strict Mode
{
    "_id": {
        "$oid" : "5716054bee6e764c94fa7ddd"
    },
    "name": "MongoDB extractor",
    "revisions": [
        {
            "id": "1c6262e",
            "desc": "First version"
        },
        {
            "id": "68fc980",
            "desc": "Second version"
        }
    ],
    "status": {
        "isActive": 1,
        "isDeleted": 0
    }
}
Mapping
{
    "_id.$oid": {
        "type": "column",
        "mapping": {
            "destination": "id",
            "primaryKey": true
        }
    },
    "name": "name",
    "status.isActive": "isActive",
    "status.isDeleted": "isDeleted",
    "revisions": {
        "type": "table",
        "destination": "extractors-revisions",
        "tableMapping": {
            "id": "id",
            "desc": "desc"
        }
    }
}
Output extractors
id (marked as PK)nameisActiveisDeleted
5716054bee6e764c94fa7dddMongoDB extractor10
extractors-revisions
iddescextractors_pk
1c6262eFirst version5716054bee6e764c94fa7ddd
68fc980Second version5716054bee6e764c94fa7ddd
As you can see, joining these two tables will be very easy.

Storing Nested Documents to Parent Table

Document
{
    "_id" : ObjectId("5716054bee6e764c94fa7ddd"),
    "name" : "MongoDB extractor",
    "revisions" : [
        {
            "id" : "1c6262e",
            "desc" : "First version"
        },
        {
            "id" : "68fc980",
            "desc" : "Second version"
        }
    ],
    "status" : {
        "isActive" : 1,
        "isDeleted" : 0
    }
}
Document in Strict Mode
{
    "_id": {
        "$oid" : "5716054bee6e764c94fa7ddd"
    },
    "name": "MongoDB extractor",
    "revisions": [
        {
            "id": "1c6262e",
            "desc": "First version"
        },
        {
            "id": "68fc980",
            "desc": "Second version"
        }
    ],
    "status": {
        "isActive": 1,
        "isDeleted": 0
    }
}
Mapping
{
    "_id.$oid": {
        "type": "column",
        "mapping": {
            "destination": "id",
            "primaryKey": true
        }
    },
    "name": "name",
    "status.isActive": "isActive",
    "status.isDeleted": "isDeleted",
    "revisions.0.desc": "revision0",
    "revisions.1.desc": "revision1"
}
The numbers after the "revision" array define the position of the object in the array. 0 is the first position.
Output extractors
id (marked as PK)nameisActiveisDeletedrevision0revision1
5716054bee6e764c94fa7dddMongoDB extractor10First versionSecond version
As you can see, the values from the "revisions" array are stored in the columns of the "extractors" table.

With Lists

Document
{
    "_id" : ObjectId("5716054bee6e764c94fa7ddd"),
    "name" : "MongoDB extractor",
    "tags" : [
        "keboola",
        "extractor",
        "mongodb"
    ]
}
Document in Strict Mode
{
    "_id": {
        "$oid" : "5716054bee6e764c94fa7ddd"
    },
    "name": "MongoDB extractor",
    "tags": [
        "keboola", "extractor", "mongodb"
    ]
}
Mapping
{
    "_id.$oid": {
        "type": "column",
        "mapping": {
            "destination": "id",
            "primaryKey": true
        }
    },
    "name": "name",
    "tags": {
        "type": "table",
        "destination": "extractors-tags",
        "tableMapping": {
            ".": {
                "mapping": {
                    "destination": "tag"
                }
            }
        }
    }
}
Output extractors
id (marked as PK)name
5716054bee6e764c94fa7dddMongoDB extractor
extractors-tags
tagextractors_pk
keboola5716054bee6e764c94fa7ddd
extractor5716054bee6e764c94fa7ddd
mongodb5716054bee6e764c94fa7ddd

Boolean Values

Documents
[
    {
        "_id" : ObjectId("764c94fa7ddd5716054bee6e"),
        "name" : "MySQL extractor",
        "isActive" : false
    }
    {
        "_id" : ObjectId("5716054bee6e764c94fa7ddd"),
        "name" : "MongoDB extractor",
        "isActive" : true
    }
]
Documents in Strict Mode
[
    {
        "_id": {
            "$oid" : "764c94fa7ddd5716054bee6e"
        },
        "name": "MySQL extractor",
        "isActive": false
    },
    {
        "_id": {
            "$oid" : "5716054bee6e764c94fa7ddd"
        },
        "name": "MongoDB extractor",
        "isActive": true
    }
]
Mapping
{
    "_id.$oid": {
        "type": "column",
        "mapping": {
            "destination": "id",
            "primaryKey": true
        }
    },
    "isActive": "isActive"
}
Output extractors
id (marked as PK)nameisActive
764c94fa7ddd5716054bee6eMySQL extractor(empty string)
5716054bee6e764c94fa7dddMongoDB extractor1