skip to main content
Welcome to the Progress DataDirect for JDBC for MongoDB Driver : Mapping Objects to Tables : Flattening Native Data
  

Try DataDirect Drivers Now

Flattening Native Data

You can use the Schema Tool to flatten MongoDB collections into relational tables. The following example shows how the source data is flattened.
A data source has a collection called employee with the following structure:
{"_id": pdn313,
"name": "Charlotte",
"manager": {"name": "Robert",
"emails": ["bob@email.com", "robert@email.com"]
}
}
The employee collection would be flattened into a relational table with the following structure:
_ID
NAME
MANAGER_NAME
MANAGER_EMAILS_0
MANAGER_EMAILS_1
pdn313
Charlotte
Robert
bob@email.com
robert@email.com
All fields are retained as separate columns in the resulting relational table. Simple types such as _id and name correspond directly to columns. In turn, subdocuments are flattened into columns using the <objectname>_<fieldname> pattern. Next, the emails array is flattened into two columns, using an extended version of the <arrayname>_<arrayindex> pattern: <objectname>_<arrayname>_<arrayindex>.
Note: As subdocuments or arrays are discovered at deeper and deeper levels, the <objectname>_<fieldname> or <arrayname>_<arrayindex> pattern is extended, for example, <objectname>_<objectname>_<fieldname>.