๐ Clean up book attributes
We want to clean up the bookAttributes array in our MongoDB schema. We want an array of objects containing attributes, modelled as key value pairs. something like:
{
"_id": 838383, // book id
"attributes": [
{
"key": "price",
"value": 11
},
{
"key": "pages",
"value": 236
},
// ...
]
}
- On the MongoDB diagram view, click on the
books
collection. - On the relational mappings list on the right, click on the edit icon of
book_attribute
embedded array mapping rule. - Change the Field name from
bookAttributes
toattributes
. - Uncheck
bookId
. We just want all the attributes, which are key/value pairs. Also, as we're embedded inside books, we don't need thebookId
anymore. - Click
Save and close
.
info
Here we've implemented the Attribute Pattern for MongoDB. This will allow for easy indexing, querying based on attributes and extension of attributes.
