Skip to main content

馃憪 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 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
  • Select Embedded documents
  • Select authors as Source table
  • In the advanced settings, check 'Merge fields into parent`
  • 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. 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 of the connect modal