There are 3 CouchDB document types:
User
{ "_id: "user/author1", "type: "user", "name" : "Joe Doe"}
Review
{ "_id: "review/review1", "type" : "review", "content" : "..." }
Product
{ "_id": "product/awesomeproduct", "type" : "product", "reviews": [
{
"author": "author1",
"review_id": "review/review1"
},
{
"author": "author2",
"review_id": "review/review2"
}
]
}
How can I get all data from documents with single view?
I try to use linked documents, but it can be use (with include_docs=true) only one per emit:
(coffescript)
(doc) ->
if doc.type is "product"
for review in doc.reviews
emit [doc._id, review.author],{_id: "user/" + review.author}
emit [doc._id, review.author],{_id: review.review_id}
But I want something like this (get user and review doc in single emit):
(doc) ->
if doc.type is "product"
for review in doc.reviews
key = [doc._id, review.author]
value = {"user:" {_id: "user/" + review.author},"review" :{_id: review.review_id}}
emit key, value
Is there any possible way how to achieve it? How to join these types of documents in single view?
I want to get something like this result:
[
key : ["product/awesomeproduct", "author1"],
value : {user: {_id: "user/author1"},review :{_id: "review/review1"}}
doc:
{user: {"_id: "user/author1", "type: "user", "name" : "Joe Doe"},
review: {"_id: "review/review1", "type" : "review", "content" : "..."}
}
]