Different Shapes in One Collection: the Polymorphic Pattern

Bikes, helmets and lights can share one products collection, each with the fields every product has, its own fields, and a type field that says which kind it is, so one query can search them all and another can pick out one kind.

By

Updated

Cheat sheet: Different Shapes in One Collection: the Polymorphic Pattern
Category
MongoDB
Level
Journeyman
Tags
mongodb, Polymorphic Pattern, Schema Design Patterns, Schemaless