Friday, 23 June 2017

Mongodb Data Model Design - Embedded data model & Reference data model

Mongodb Data Model Design - Embedded data model & Reference  data model

Question: What is Data Model Design?
Data modeling is first step in database design and object-oriented programming as the designers. It start from conceptual model to logical model to physical schema.


Question: What are different type of Data Model Design?
  1. Embedded Data Models
  2. Reference Data Models



Question: What is Embedded Data Model?
In Embedded Data Model, we store all releated in single document.
For example:
there is a user with name of salman and he has multiple address in different countries.
In this Embedded model, we store the address along with his details. means address and user details in single document.


Question: Give example of embedded Data Model?
One user 'Salman" have multiple address (2 address).
{
  name: 'Salman',
  ssn: '123-456-7890',
  addresses: [
    {
      street: '123 Sesame St',
      city: 'jaipur',
      cc: 'IN'
    },
    {
      street: '123 Avenue Q',
      city: 'New York',
      cc: 'USA'
    }
  ]
}



Question: Where embedded Data Model are good to used?
  1. Data that does not change regularly
  2. Document that grow by a small amount
  3. Data that you'll often need to perform ascending query to fetch
  4. Fast reading speed



Question: What is Normalized Data Models OR Reference Data Model?
In Normalized Data model, we store the user information in multiple collections.
For example,
Single user have multiple address.
Store the user details in user collections.
Store the user address in address collections.
in address collection, we set the reference to user collection.


Question: Give example of Normalized Data Models OR Reference Data Model?
One user 'Salman" have multiple address (2 address).
User collection
{
  id: 100
  name: 'Salman',
  ssn: '123-456-7890',
  
}

User's address collection
 {
      street: '123 Sesame St',
      city: 'jaipur',
      cc: 'IN',
      user_id:100
    }
 {
      street: '123 Avenue Q',
      city: 'New York',
      cc: 'USA',
     user_id:100
}



Question: Where Reference Data Model are good to used?
  1. Large sub documents
  2. When immediate consistency is necessary
  3. Document grow with a large amount
  4. Fast write speed



No comments :

Post a Comment