Mapping Examples
Basic Mapping Without Nested Documents
Section titled “Basic Mapping Without Nested Documents”| Document | ```javascript { "_id" : ObjectId("5716054bee6e764c94fa7ddd"), "name" : "MongoDB extractor" } ``` | ||||
| Document in Strict Mode | ```json { "_id": { "$oid" : "5716054bee6e764c94fa7ddd" }, "name": "MongoDB extractor" } ``` | ||||
| Mapping | ```json { "_id.$oid": "id", "name": "name" } ``` | ||||
| Output |
extractors
|
Defining Primary Key
Section titled “Defining Primary Key”| Document | ```javascript { "_id" : ObjectId("5716054bee6e764c94fa7ddd") } ``` | ||
| Document in Strict Mode | ```json { "_id": { "$oid" : "5716054bee6e764c94fa7ddd" } } ``` | ||
| Mapping | ```json { "_id.$oid": { "type": "column", "mapping": { "destination": "id", "primaryKey": true } } } ``` | ||
| Output |
extractors
|
Mapping with Nested Documents
Section titled “Mapping with Nested Documents”| Document | ```javascript { "_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 | ```json { "_id": { "$oid" : "5716054bee6e764c94fa7ddd" }, "name": "MongoDB extractor", "revisions": [ { "id": "1c6262e", "desc": "First version" }, { "id": "68fc980", "desc": "Second version" } ], "status": { "isActive": 1, "isDeleted": 0 } } ``` | |||||||||||||||||
| Mapping | ```json { "_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
extractors-revisions
As you can see, joining these two tables will be very easy. |
Storing Nested Documents to Parent Table
Section titled “Storing Nested Documents to Parent Table”| Document | ```javascript { "_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 | ```json { "_id": { "$oid" : "5716054bee6e764c94fa7ddd" }, "name": "MongoDB extractor", "revisions": [ { "id": "1c6262e", "desc": "First version" }, { "id": "68fc980", "desc": "Second version" } ], "status": { "isActive": 1, "isDeleted": 0 } } ``` | ||||||||||||
| Mapping |
```json
{
"_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
As you can see, the values from the “revisions” array are stored in the columns of the “extractors” table. |
With Lists
Section titled “With Lists”| Document | ```javascript { "_id" : ObjectId("5716054bee6e764c94fa7ddd"), "name" : "MongoDB extractor", "tags" : [ "keboola", "extractor", "mongodb" ] } ``` | ||||||||||||
| Document in Strict Mode | ```json { "_id": { "$oid" : "5716054bee6e764c94fa7ddd" }, "name": "MongoDB extractor", "tags": [ "keboola", "extractor", "mongodb" ] } ``` | ||||||||||||
| Mapping | ```json { "_id.$oid": { "type": "column", "mapping": { "destination": "id", "primaryKey": true } }, "name": "name", "tags": { "type": "table", "destination": "extractors-tags", "tableMapping": { ".": { "mapping": { "destination": "tag" } } } } } ``` | ||||||||||||
| Output |
extractors
extractors-tags
|
Boolean Values
Section titled “Boolean Values”| Documents | ```javascript [ { "_id" : ObjectId("764c94fa7ddd5716054bee6e"), "name" : "MySQL extractor", "isActive" : false } { "_id" : ObjectId("5716054bee6e764c94fa7ddd"), "name" : "MongoDB extractor", "isActive" : true } ] ``` | |||||||||
| Documents in Strict Mode | ```json [ { "_id": { "$oid" : "764c94fa7ddd5716054bee6e" }, "name": "MySQL extractor", "isActive": false }, { "_id": { "$oid" : "5716054bee6e764c94fa7ddd" }, "name": "MongoDB extractor", "isActive": true } ] ``` | |||||||||
| Mapping | ```json { "_id.$oid": { "type": "column", "mapping": { "destination": "id", "primaryKey": true } }, "isActive": "isActive" } ``` | |||||||||
| Output |
extractors
|