Database Reference
In-Depth Information
class
class Photo
Photo ( Document ):
...
short_description = Field ( 'sd' , str , if_missing = '' )
...
Using such a schema, Ming will lazily migrate documents as they are loaded from the data-
base, as well as renaming the short_description field (in Python) to the sd property (in
BSON).
Polymorphic Schemas Support Semi-Structured Domain
Data
In some applications, we may want to store semi-structured domain data. For instance, we
may have a product table in a database where products may have various attributes, but not
all products have all attributes. One approach to such modeling, of course, is to define all the
product classes we're interested in storing and use the object-oriented mapping approach just
described. There are, however, some pitfalls to avoid when this approach meets data in the
real business world:
▪ Product hierarchies may change frequently as items are reclassified
▪ Many products, even within the same class, may have incomplete data
For instance, suppose we are storing a database of disk drives. Although all drives in our in-
ventory specify capacity, some may also specify the cache size, while others omit it. In this
case, we can use a generic properties subdocument containing the variable fields:
{
_id : ObjectId (...),
price : 499.99 ,
title : 'Big and Fast Disk Drive' ,
gb_capacity : 1000 ,
properties : {
'Seek Time' : '5ms' ,
'Rotational Speed' : '15k RPM' ,
'Transfer Rate' : '...'
... }
}
Search WWH ::




Custom Search