I've been researching MongoDB and trying to see if it would be a fit for my company's product catalog.
I came across database references: http://docs.mongodb.org/manual/reference/database-references/ and had some questions about how exactly to link documents together.
Assume we have two db.categories
and db.products
collections... I have documents in db.products
that need to link to their categories in db.categories
.
I have a "category" field in db.products
that I will store the objectID of the category document in. However, I do not see a way to specify that this objectID references the db.categories
collection.
Do I need to use DBREFs?
Below is a brief example of my data...
Document in db.categories
:
{
"_id" : ObjectId("546b72a47ea1d03593000158"),
"name" : "Category1",
"type" : "type1 of category1",
"spec_columns" : [
{
"field" : "capacity",
"display" : "Capacity (tons)"
},
{
"field" : "weight",
"display" : "Weight (lbs)"
}
]
}
Document in db.products
:
{
"_id" : ObjectId("546a575f7ea1d03593000154"),
"model" : "NER003H",
"category" : ObjectId("546b72a47ea1d03593000158"),
"capacity" : "1/2",
"weight" : 10
}
Any help, suggestions and advice is welcome and greatly appreciated.
Darius