1
votes

I have posts documents and user documents how are authors of this posts. I need to get all posts which are at a given venue and for those posts the corresponding user/author documents as well.

Post:

{
   "_id": "53551d9e92436f69ae04a104c2000b82",
   "content": "heythere!",
   "author": "a4df7fe1226fedb80f6c2dc13e000af5",
   "venue": "51434246e4b0601fde0cf2eb",
   "type": "post"
}

User:

{
  "_id": "a4df7fe1226fedb80f6c2dc13e000af5",
  "username": "sep o sep",
  "type" : "user"
}

Is it possible to emit keys in the way that i will get posts to a given location along with the user documents to that posts in one couchdb query?

1

1 Answers

0
votes

Check out the wiki, there's a feature called "linked documents" that allow you to retrieve related documents in a single view query.

The wiki will give a full explanation, but the gist is that you emit an object with an _id property in your view function for each related document. (since you have the id contained in your parent document) When include_docs=true is used in your view query, CouchDB knows to retrieve the documents you emitted rather than the source.