Data Modeling Flashcards

1
Q

What are the 3 different types of data relationships?
Give examples

A
  • One-to-one: User => Name
  • One-to-many: User => Tasks
  • Many-to-many => Products => Categories
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between normalized and denormalized data in MongoDB?

A

In the context of MongoDB, normalized data is data that is divided into different collections which normally improves write performance but decreases read performance. Normalized data does not support data duplication. Denormalized data is data that is combined from multiple collections into a single collection which normally improves query performance but decreases write performance. Denormalized data supports data duplication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 2 ways to model data in MongoDB?

A
  • Embedding documents (denormalizing)
  • Referencing documents (normalizing)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 3 steps of the schema design process?

A
  1. Identify the operations that your application runs most frequently
  2. Identify the relationships in your application’s data and decide whether to reference or embed related data
  3. Apply schema design patterns to optimize reads and writes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When might data duplication be beneficial?
Give an example

A

Given collection A and collection B, where A uses a subset of the data in B, and that data is not updated frequently, duplication might be beneficial. For example:

A product collection uses the 5 most recent documents from the review collection. In this case, instead of using references, code duplication could be beneficial since reviews are not updated frequently and keeping the data consistent between the collections is not a major task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the behavior of the following code:

db.customers.insertOne( {
   customerId: 123,
   name: "Alexa Edwards",
   email: "a.edwards@randomEmail.com",
   phone: "202-555-0183"
} )

db.products.insertOne( {
   productId: 456,
   product: "sweater",
   price: 30,
   size: "L",
   material: "silk",
   manufacturer: "Cool Clothes Co"
} )

db.orders.insertOne( {
   orderId: 789,
   customerId: 123,
   totalPrice: 45,
   date: ISODate("2023-05-22"),
   lineItems: [
       {
          productId: 456,
          product: "sweater",
          price: 30,
          size: "L"
       },
       {
          productId: 809,
          product: "t-shirt",
          price: 10,
          size: "M"
       },
       {
          productId: 910,
          product: "socks",
          price: 5,
          size: "S"
       }
   ]
} )
A

The code displays a logical approach to duplicating product documents (with specific fields) inside order documents

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Review

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Review

A
db.articles.insertOne(
   {
      title: "My Favorite Vacation",
      date: ISODate("2023-06-02"),
      text: "We spent seven days in Italy...",
      tags: [
         {
            name: "travel",
            url: "<blog-site>/tags/travel"
         },
         {
            name: "adventure",
            url: "<blog-site>/tags/adventure"
         }
      ],
      comments: [
         {
            name: "pedro123",
            text: "Great article!"
         }
      ],
      author: {
         name: "alice123",
         email: "alice@mycompany.com",
         avatar: "photo1.jpg"
      }
   }
)

or

db.articles.insertOne(
   {
      title: "My Favorite Vacation",
      date: ISODate("2023-06-02"),
      text: "We spent seven days in Italy...",
      authorId: 987,
      tags: [
         {
            name: "travel",
            url: "<blog-site>/tags/travel"
         },
         {
            name: "adventure",
            url: "<blog-site>/tags/adventure"
         }
      ],
      comments: [
         {
            name: "pedro345",
            text: "Great article!"
         }
      ]
   }
)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are MongoDB’s 5 main anti-pattern?

A
  1. Unbounded document size
  2. Massive number of collections
  3. Reading without indexes
  4. Redundant indexes
  5. Data that is accessed together is not stored together
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 2 tools that MongoDB Atlas provides to identify anti-patterns?

A
  1. Data explorer
  2. Performance Advisor (Tier M10)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly