I am a new in MongoDB and, in its docs, there is the following phrase as a MongoDB advantage:
Dynamic schema supports fluent polymorphism
What does it mean exactly?
Join Stack Overflow to learn, share knowledge, and build your career.
I am a new in MongoDB and, in its docs, there is the following phrase as a MongoDB advantage:
Dynamic schema supports fluent polymorphism
What does it mean exactly?
A polymorphic type is one whose operations can also be applied to values of some other type, or types. Lets have an example,consider the following mongodb collection of cars
A basic car structure
{
"TYPE": "BASIC CAR",
"MAX_SPEED": 100,
"MILEAGE": 20,
"GEARS": 4,
"FEATURES": [
{
"AC": "yes"
}
]
}
The first 4 keys will be same for almost all cars ----> polymorphic type
A sports car
{
"TYPE": "SPORTS CAR",
"MAX_SPEED": 300,
"MILEAGE": 10,
"GEARS": 8,
"FEATURES": [
{
"AC": "yes"
},
{
"NITRO": "yes"
},
{
"NAVIGATION": "yes"
},
.
.
.
.
... so on
]
"ADVANCED PROTECTION" : "yes",
"SENSORS" : [
{"OBSTACLE" : "yes"}
]
}
The sports inherits the features of BASIC CAR and also has some its own features, that's satisfies Polymorphism.
And coming to the part Dynamic Schema we can see that structure of document is different for both documents MongoDB won't restrict to a particular structure so that's satisfies Dynamic Schema.