đź’ˇ Tip and Trick: MongoDB Polymorphic & Outlier Pattern đź’ˇ

🔍 Scale:

Cheaper
Flexibility to scale horizontally through sharding
Distributing data across multiple servers
When database exceeds capacity, sharding and split it over two servers

🔍 BSON:

Binary representation of JSON (JavaScript Object Notation…


This content originally appeared on DEV Community and was authored by Danny Chan

🔍 Scale:

  • Cheaper
  • Flexibility to scale horizontally through sharding
  • Distributing data across multiple servers
  • When database exceeds capacity, sharding and split it over two servers


🔍 BSON:

  • Binary representation of JSON (JavaScript Object Notation) documents
  • Data types: Double, String, Object, Array, Binary Data, ObjectId, Boolean, Date, Null, Regular Expression, JavaScript, 32-bit Integer, Timestamp, 64-bit Integer, Decimal128, Min Key, Max Key


🗄️ Documents:

  • Grouped together in collections
  • 16 megabyte size limit
  • Related collections are grouped together and stored in a database


🔑 _id:

  • Unique for each document in a collection
  • Immutable
  • Any type (cannot be array)


🤯 Challenge:

  • Access data together should be stored together
  • Storage is a small cost, developers are expensive
  • Instead of optimizing for storage, optimize for developers' time
  • Implementing business logic
  • Optimize data model for developer productivity and query optimization


🔍 Validation Option:

  • Choice of throwing an error or a warning if a validation rule is violated


🤟 Embrace Document Diversity:

  • Not all documents in a collection need to have the same fields


🤖 Polymorphic Pattern:

  • Collections are of similar, but not identical
  • Grouping documents together based on the queries
  • Example:
{
    "type": "singles",
    "titles": 167
}
{
    "type": "doubles",
    "titles": 177,
    "tournaments": 233
}


🤯 Outlier Pattern:

  • Solve outlier use case (a document has millions of embedding data)
  • Add has_extras fields
  • Create a new document where store other embedding data
  • Example:
{
    "author": "Ken W. Alger",
    "customers_purchased": ["user00", "user01"]
}
{
   "author": "J.K. Rowling",
   "customers_purchased": ["user00", ..., "user999"],
   "has_extras": "true"
}


🤯 Reference:

https://www.mongodb.com/developer/products/mongodb/polymorphic-pattern/
Building with Patterns: The Polymorphic Pattern

https://www.mongodb.com/blog/post/building-with-patterns-the-outlier-pattern
Building With Patterns: The Outlier Pattern

Editor

Image description

Danny Chan, specialty of FSI and Serverless

Image description

Kenny Chan, specialty of FSI and Machine Learning


This content originally appeared on DEV Community and was authored by Danny Chan


Print Share Comment Cite Upload Translate Updates
APA

Danny Chan | Sciencx (2024-08-05T15:35:24+00:00) đź’ˇ Tip and Trick: MongoDB Polymorphic & Outlier Pattern đź’ˇ. Retrieved from https://www.scien.cx/2024/08/05/%f0%9f%92%a1-tip-and-trick-mongodb-polymorphic-outlier-pattern-%f0%9f%92%a1/

MLA
" » đź’ˇ Tip and Trick: MongoDB Polymorphic & Outlier Pattern đź’ˇ." Danny Chan | Sciencx - Monday August 5, 2024, https://www.scien.cx/2024/08/05/%f0%9f%92%a1-tip-and-trick-mongodb-polymorphic-outlier-pattern-%f0%9f%92%a1/
HARVARD
Danny Chan | Sciencx Monday August 5, 2024 » đź’ˇ Tip and Trick: MongoDB Polymorphic & Outlier Pattern đź’ˇ., viewed ,<https://www.scien.cx/2024/08/05/%f0%9f%92%a1-tip-and-trick-mongodb-polymorphic-outlier-pattern-%f0%9f%92%a1/>
VANCOUVER
Danny Chan | Sciencx - » đź’ˇ Tip and Trick: MongoDB Polymorphic & Outlier Pattern đź’ˇ. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/05/%f0%9f%92%a1-tip-and-trick-mongodb-polymorphic-outlier-pattern-%f0%9f%92%a1/
CHICAGO
" » đź’ˇ Tip and Trick: MongoDB Polymorphic & Outlier Pattern đź’ˇ." Danny Chan | Sciencx - Accessed . https://www.scien.cx/2024/08/05/%f0%9f%92%a1-tip-and-trick-mongodb-polymorphic-outlier-pattern-%f0%9f%92%a1/
IEEE
" » đź’ˇ Tip and Trick: MongoDB Polymorphic & Outlier Pattern đź’ˇ." Danny Chan | Sciencx [Online]. Available: https://www.scien.cx/2024/08/05/%f0%9f%92%a1-tip-and-trick-mongodb-polymorphic-outlier-pattern-%f0%9f%92%a1/. [Accessed: ]
rf:citation
» đź’ˇ Tip and Trick: MongoDB Polymorphic & Outlier Pattern đź’ˇ | Danny Chan | Sciencx | https://www.scien.cx/2024/08/05/%f0%9f%92%a1-tip-and-trick-mongodb-polymorphic-outlier-pattern-%f0%9f%92%a1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.