Question
You maintain a relational database for a book publisher. The database contains the following tables.
| Name | Column |
|---|---|
| Author | authorId (primary key) |
| | fullname |
| | address |
| | contactinfo |
| Book | bookId (primary key) |
| | isbn |
| | title |
| | genre |
| Bookauthorlnk | authorId (foreign key) |
| | bookId (foreign key) |
The most common query lists the books for a given authorId.
You need to develop a non-relational data model for Azure Cosmos DB for NoSQL that will replace the relational database. The solution must minimize latency and read operation costs.
What should you include in the solution?
- A. Create a container for Author and a container for Book. In each Author document, embed bookId for each book by the author. In each Book document embed authorId of each author.
- B. Create Author, Book, and Bookauthorlnk documents in the same container.
- C. Create a container that contains a document for each Author and a document for each Book. In each Book document, embed authorId. Correct
- D. Create a container for Author and a container for Book. In each Author document and Book document embed the data from Bookauthorlnk.
Explanation
Storing authors and books in one container and embedding authorId in each Book document lets the most common request, list the books for an authorId, be answered by a single query on one container, ideally within one logical partition when authorId is the partition key. Options A and D split the data across two containers, so listing an author's books needs one read for the author's book IDs and then more reads in the Book container, raising latency and RU cost. Option B keeps the relational link documents, which still forces multiple lookups to resolve the books.