couchdb - How to link more documents in one view -


there 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 data documents single view?

i try use linked documents, can use (with include_docs=true) 1 per emit:

(coffescript)

(doc) ->   if doc.type "product"     review in doc.reviews        emit [doc._id, review.author],{_id: "user/" + review.author}        emit [doc._id, review.author],{_id: review.review_id} 

but want (get user , review doc in single emit):

 (doc) ->   if doc.type "product"     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 possible way how achieve it? how join these types of documents in single view?

i want 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" : "..."}      }  ] 

short anwser...you can't. couchdb allows emit single document @ time.

there 2 approaches getting data need.

  1. keep structure as-is , perform join manually in client code.
  2. denormalize data. denormalizing here placing reviews inside product document.

data modeling considerations mongodb concepts how structure data in nosql environment same couchdb


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -