I'm new to MongoDB and am trying to design a simple schema for a set of python objects. I'm having a tough time working with the concept of polymorphism.
Below is some pseudo-code. How would you represent this inheritance hierarchy in MongoDB schema:
class A:
content = 'video' or 'image' or 'music'
data = contentData # where content may be video or image or music depending on content.
class videoData:
length = *
director = *
actors = *
class imageData:
dimensions = *
class musicData:
genre = *
The problem I'm facing is that the schema of A.data depends on A.content. How can A be represented in a mongodb schema?
Your documents could look like this:
{ _type: "video",
data: {
length: 120,
director: "Smith",
actors = ["Jones", "Lee"]
}
}
So, basically, "data" points to an embedded document with the document's type-specified fields.
This doesn't particularly answer your question, but you might check out Ming. It does polymorphism for you when it maps the document to the object.
http://merciless.sourceforge.net/tour.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With