Databases Reference
In-Depth Information
... };
{ “_id” : “regular”, “unit_price” : 2 }
> db.products2.save(p4);
> db.products2.save(p5);
> db.products2.save(p6);
coffee_order.txt
Verify that all the three products are in the collection:
> db.products.find();
{ “_id” : ObjectId(“4ccd1209d3c7ab3d1941b105”), “name” : “latte”,
“unit_price” : 4 }
{ “_id” : ObjectId(“4ccd1373d3c7ab3d1941b106”), “name” : “cappuccino”,
“unit_price” : 4.25 }
{ “_id” : ObjectId(“4ccd1377d3c7ab3d1941b107”), “name” : “regular”,
“unit_price” : 2 }
Available for
download on
Wrox.com
coffee_order.txt
Next, defi ne a new orders collection, called orders3 , and use DBRef to establish the relationship
between orders3 and products . The orders3 collection can be defi ned as follows:
t3 = {
... order_date: new Date(),
... “line_items”: [
... {
... “item_name”: new DBRef('products2', p4._id),
... “quantity:1
... },
... {
... “item_name”: new DBRef('products2', p5._id),
... “quantity”:1
... },
... {
... “item_name”: new DBRef('products2', p6._id),
... “quantity”:2
... }
... ]
... };
Available for
download on
Wrox.com
db.orders3.save(t3);
coffee_order.txt
The MongoDB creation process is fairly simple and as you saw, some aspects of the relationship
can also be formally established using DBRef . Next, the create operation is viewed in the context of
column-oriented databases.
Search WWH ::




Custom Search