|
1 |
| -.. _mapping-rule-embedded-array: |
| 1 | +.. _rm-embedded-array: |
2 | 2 |
|
3 | 3 | ==============
|
4 | 4 | Embedded Array
|
5 | 5 | ==============
|
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 1 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +The :guilabel:`Embedded array` mapping rule is an advanced mapping rule option. |
| 14 | +It must be explicitly added to a mapping model. |
| 15 | + |
| 16 | +About this Task |
| 17 | +--------------- |
| 18 | + |
| 19 | +The :guilabel:`Embedded array` mapping rule is available if the relational |
| 20 | +table it is mapping from is on the many side of the foreign key relationship. |
| 21 | + |
| 22 | +The table containing the primary key must also be mapped to a |
| 23 | +collection in the MongoDB model. |
| 24 | + |
| 25 | +Behavior |
| 26 | +-------- |
| 27 | + |
| 28 | +Use the :guilabel:`Embedded array` mapping rule to insert the |
| 29 | +values of the child table as array elements under documents in |
| 30 | +the collection mapped to the parent table. |
| 31 | + |
| 32 | +Example |
| 33 | +------- |
| 34 | + |
| 35 | +This section demonstrates the relational input and |
| 36 | +the MongoDB output of the :guilabel:`Embedded array` mapping rule. |
| 37 | + |
| 38 | +Embedded array |
| 39 | +~~~~~~~~~~~~~~ |
| 40 | + |
| 41 | +In this example: |
| 42 | + |
| 43 | +- An :guilabel:`Embedded Array` mapping rule is applied to the :guilabel:`Customer` table. |
| 44 | +- The :guilabel:`Source table` is set to :guilabel:`Order`. |
| 45 | +- The :guilabel:`Prefix` is set to :guilabel:`(root)`. |
| 46 | +- The :guilabel:`Field Name` is set to :guilabel:`orders`. |
| 47 | + |
| 48 | + |
| 49 | +Click the tabs below to see the input and output for this example: |
| 50 | + |
| 51 | +.. tabs:: |
| 52 | + |
| 53 | + .. tab:: Relational Input |
| 54 | + :tabid: Embedded-array-in |
| 55 | + |
| 56 | + ``Customer`` table: |
| 57 | + |
| 58 | + .. list-table:: |
| 59 | + :header-rows: 1 |
| 60 | + |
| 61 | + * - Id |
| 62 | + - Name |
| 63 | + - Address1 |
| 64 | + - Address2 |
| 65 | + - Address3 |
| 66 | + * - 1 |
| 67 | + - Joelynn Fawthrop |
| 68 | + - 86 Dwight Pass |
| 69 | + - Carregal |
| 70 | + - 3800-854 |
| 71 | + |
| 72 | + ``Orders`` table: |
| 73 | + |
| 74 | + .. list-table:: |
| 75 | + :header-rows: 1 |
| 76 | + |
| 77 | + * - OrderID |
| 78 | + - CustomerID |
| 79 | + - TotalAmount |
| 80 | + - OrderStatusID |
| 81 | + * - 1 |
| 82 | + - 1 |
| 83 | + - 50.00 |
| 84 | + - 1 |
| 85 | + * - 4 |
| 86 | + - 1 |
| 87 | + - 500.00 |
| 88 | + - 3 |
| 89 | + |
| 90 | + .. tab:: MongoDB Output |
| 91 | + :tabid: Embedded-array-out |
| 92 | + |
| 93 | + The document in the ``Customer`` collection now has the ``Order`` details |
| 94 | + embedded as an array of objects field called ``Orders``. |
| 95 | + |
| 96 | + All of the customers orders are now visible in the ``Customer`` collection |
| 97 | + as an array of nested documents. |
| 98 | + |
| 99 | + .. code-block:: javascript |
| 100 | + :copyable: false |
| 101 | + :emphasize-lines: 7-19 |
| 102 | + |
| 103 | + { |
| 104 | + "_id": { "CustomerID": 1 }, |
| 105 | + "Name": "Joelynn Fawthrop", |
| 106 | + "Address1": "86 Dwight Pass", |
| 107 | + "Address2": "Carregal", |
| 108 | + "Address3": "3800-854", |
| 109 | + "Orders": |
| 110 | + [ |
| 111 | + { "OrderID": 1, |
| 112 | + "CustomerID": 1, |
| 113 | + "TotalAmount": 50, |
| 114 | + "OrderStatusID": 1 |
| 115 | + }, |
| 116 | + { "OrderID": 4, |
| 117 | + "CustomerID": 1, |
| 118 | + "TotalAmount": 500, |
| 119 | + "OrderStatusID": 1 |
| 120 | + } |
| 121 | + ] |
| 122 | + } |
0 commit comments