couchdb - How To Get Parent Details In Couch Db? -
please me
i have created databse named product
and have created 2 product documents id 'p101','p102'
{ "_id": "p101", "_rev": "5-8d1c4b5b7f6e65a5997d4ec5b4346e5f", "type": "product", "name": "shirt", "hersteller": "oska", "price": 11.15 }
{ "_id": "p102", "_rev": "3-8ad956f0c524b1a2396ebdda1ed0afbe", "type": "product", "name": "pullover", "hersteller": "acme", "price": 7.58 }
now added 1 order document 'p101' parent
{ "_id": "ord-101", "_rev": "7-dbd8cca3b6dc9f4cb3b8bb7e4aec6630", "type": "order", "orderdate": "01.01.2012", "parentprodct": "p101" }
now have added report document 'ord-101' parent
{ "_id": "report-101", "_rev": "10-c57e3c039a44d95d6bd40d8a83a951da", "type": "report", "parentorder": "ord-102" }
after have added design document corresponding view functions
{ "_id": "_design/proddesign", "_rev": "87-d1b0a8c8cdfe569bbf9805df4918af4f", "rev": "3-productrev", "views": {
"fifth": { "map": "function(doc){if(doc.type=='report'){emit(doc._id,{_id:doc.reportdet});}}" } } }
.. give me parent off report document.actually want print details of corresponding parent of order document also.
ie details 'p101' also..
how can achive ..pls help
assuming following data (note: _rev , unused docs removed example):
{ "_id": "p101", "type": "product", "name": "shirt", "hersteller": "oska", "price": 11.15 } { "_id": "ord-101", "type": "order", "orderdate": "01.01.2012", "product": "p101" } { "_id": "report-101", "type": "report", "order": "ord-101", "product": "p101" }
you'll want along lines of:
if doc.type == "product" emit([doc.id], doc.type) if doc.type == "order" emit([doc.product, doc.id], doc.type) if doc.type == "report" emit([doc.product, doc.order, doc.id], doc.type)
which result in view output like:
[ [["p101"], "product"], [["p101", "ord-101"], "order"], [["p101", "ord-101", "report-101"], "report"] ]
which if query
?startkey=["p101"]&endkey=["p101",{}]
will give product p101 of orders , reports product.
Comments
Post a Comment