Skip to main content

馃憪 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:

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

to an array of primitive values

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
  • Uncheck bookId
  • In the advanced settings, check create array of primitive values
  • Click Save and close
Screenshot of the connect modal