Embedded Documents
On this page
The Embedded Documents mapping rule is an advanced mapping rule option. It must be explicitly added to a mapping model.
About this Task
The Embedded Documents mapping rule is available if the relational table it is mapping from is on the one side of the foreign key relationship.
The table containing the foreign key must also be mapped to a collection in the MongoDB model.
Behavior
Use the Embedded Documents mapping rule to denormalize a foreign key relationship. With Embedded Documents you can nest child foreign key fields in a parent collection.
You have two main options when denormalizing your relational data with the Embedded Documents option:
You can embed the child documents into the parent and designate a Prefix and Field name to embed fields as sub documents.
You can merge into the parent, which represents the rows as fields at the parent level.
Examples
This section demonstrates the relational input and the MongoDB output of the Embedded Documents mapping rule.
Embedded Documents
In this example:
A Embedded Documents mapping rule is applied to the
Order
table.The
OrderLine
table has two rows and theOrder
table has one row.The parent collection is set to OrderLine.
Merge fields into the parent is not selected.
The Field name is set to order.
Click the tabs below to see the input and output for this example:
Merge fields into the parent
In this example:
The
OrderLine
table has four rows and the Order table has three rows.A Embedded Documents mapping rule is applied to the
Order
table.The parent collection is set to OrderLine.
Merge fields into the parent is selected.
The Prefix is set to (root).
Click the tabs below to see the input and output for this example: