Database Reference
In-Depth Information
Table 2-2. “Pages” table
node_id text
1
Welcome to my wonderful wiki.
2
This is text that is about the wiki.
Table 2-3. “Photos” table
node_id content
3
… binary data …
In MongoDB, on the other hand, we can store all of our content node types in the same col-
lection, storing only
relevant
fields in each document:
// "Page" document (stored in "nodes" collection")
{
_id
:
1
,
title
:
"Welcome"
,
url
:
"/"
,
type
:
"page"
,
text
:
"Welcome to my wonderful wiki."
}
...
// "Photo" document (also in "nodes" collection)
{
_id
:
3
,
title
:
"Cool Photo"
,
url
:
"/photo.jpg"
,
type
:
"photo"
,
content
:
Binary
(...)
}
IfweusesuchapolymorphicschemainMongoDB,wecanusethesamecollectiontoperform
queries on common fields shared by all content nodes, as well as queries for only a particular
node type. For instance, when deciding what to display for a given URL, the CMS needs to