Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ We want to clean up the book_attributes array in our MongoDB schema. We want an
- Uncheck `bookId`. We just want all the attributes, which are key/value pairs.
- Click `Save and close`

Here we've implemented the [Attribute Pattern](https://www.mongodb.com/developer/products/mongodb/attribute-pattern/) for MongoDB.

:::info
Here we've implemented the [Attribute Pattern](https://www.mongodb.com/developer/products/mongodb/attribute-pattern/) for MongoDB. This will allow for easy indexing, querying based on attributes and extension of attributes.
:::

<Screenshot url="https://www.mongodb.com/products/tools/relational-migrator" src="img/150-image-001.png" alt="Screenshot of the connect modal" />

Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Screenshot from "@site/src/components/Screenshot";

# 👐 Edit mapping to issueDetails collection (from issue_details table)
# 🦸 Edit mapping to issueDetails collection (from issue_details table)

:::info
Extra activity! Do it if you have extra time or are following along at home. It won't be covered during the hands-on lab.
:::

Now we want to remove some unncessary id fields from the issueDetails collection

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Screenshot from "@site/src/components/Screenshot";

# 👐 Add mapping to reviews collection (from users table)
# 🦸 Add mapping to reviews collection (from users table)

:::info
Extra activity! Do it if you have extra time or are following along at home. It won't be covered during the hands-on lab.
:::

We want to store each user's name against their reviews.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
import Screenshot from "@site/src/components/Screenshot";

# 👐 Add genres to books (not only genre ids)
# 👐 Change genres in books

We want to modify the MongoDB schema so that each book's genres are represented as an array of strings. We'll have data duplication, as genres will get copied on each book. This is a good strategy if the duplicated data does not change often.

We'll go from the proposed array of objects:

```json
bookGenres: [
{
bookId: "Some Book Id",
genres: "fiction"
},
{
bookId: "Some Book Id",
genres: "novel"
}
]
```

to an array of primitive values

```json
genres: [ "fiction", "novel" ]
```

- On the MongoDB diagram view, click the `books` collection
- On the relational mappings list on the right, click on the edit icon of `book_genre` embedded array
- Change the field name from `bookGenres` to `genres`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Screenshot from "@site/src/components/Screenshot";
# 👐 Add authors details to the books collection

We want to modify the MongoDB schema so that each book contains an array of its authors.
In this step we will embed the book details into the empty array from the join table (which right now only contains `authorId` and `bookId`)
In this step we will embed the book details into the empty array created from the join table (which right now only contains `authorId` and `bookId`)

- On the MongoDB diagram view, click the `books` collection
- On the relational mappings list on the right, click `+ Add`
Expand All @@ -13,8 +13,9 @@ In this step we will embed the book details into the empty array from the join t
- Check the `id` and `name` fields and uncheck the rest
- Click `Save and close`



:::info
This is a perfect example of the [Extended Reference Pattern](https://www.mongodb.com/blog/post/building-with-patterns-the-extended-reference-pattern). When we read a book, we have some of the author's data (`name` in this case) but we still have the author's id in case we need all the author's attributes (we can then do a join on read using `$lookup`)
:::

<Screenshot url="https://www.mongodb.com/products/tools/relational-migrator" src="img/130-image-001.png" alt="Screenshot of the connect modal" />

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import Screenshot from "@site/src/components/Screenshot";
# 👐 Add last three reviews to each book (from reviews table)

We want to modify the MongoDB schema so that each book contains an array of its latest three reviews.
This is actually an implementation of the [Subset Pattern](https://www.mongodb.com/blog/post/building-with-patterns-the-subset-pattern).

:::info
This is an implementation of the [Subset Pattern](https://www.mongodb.com/blog/post/building-with-patterns-the-subset-pattern).
:::

In this step we will embed the book details into the empty array from the join table.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Screenshot from "@site/src/components/Screenshot";

# 👐 Edit mapping to authors collection (from author_book table)
# 🦸 Edit mapping to authors collection (from author_book table)

:::info
Extra activity! Do it if you have extra time or are following along at home. It won't be covered during the hands-on lab.
:::

We want to modify the authors collection to include an array of IDs representing their books.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Screenshot from "@site/src/components/Screenshot";

# 👐 Add mapping to issueDetails collection (from books table)
# 🦸 Add mapping to issueDetails collection (from books table)

:::info
Extra activity! Do it if you have extra time or are following along at home. It won't be covered during the hands-on lab.
:::

Now we want to store more details from each book into the collection tracking library loans.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Screenshot from "@site/src/components/Screenshot";

# 👐 Add mapping to issueDetails collection (from users table)
# 🦸 Add mapping to issueDetails collection (from users table)

:::info
Extra activity! Do it if you have extra time or are following along at home. It won't be covered during the hands-on lab.
:::

Now we want to store more details from each user into the collection tracking library loans.

Expand Down
7 changes: 7 additions & 0 deletions docs/80-edit-mapping-rules/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"label": "👐 Edit Mapping Rules",
"link": {
"type": "generated-index",
"description": "."
}
}