Some information may be left in the same document, and in most cases this will work fine.
{ "title": "Blog Article Title", "content": "... blah blah blah ...", "author": { "name": "someguy", "email": " someguy@foo.bar " }, "type": "post" }
In other cases, you can simply use the _id another document to create a link between two documents.
{ "_id": "...", "title": "Blog Article Title", "content": "... blah blah blah ...", "author": "someguy", "type": "post" } { "_id": "someguy", "name": "Some Guy", "email": " someguy@foo.bar ", "type": "author" }
At first glance, you will need two separate queries to retrieve both objects. However, there is a nice little trick that query views can view.
function (doc) { if (doc.type === "post") { emit([doc.title, 0], null);
Your view will output this result: (note how the view is sorted)
{ ... "rows": [ { "key": ["Blog Article Title", 0], "value": null }, { "key": ["Blog Article Title", 1], "value": { "_id": "someguy" } } ] }
This is not all that is useful as it is, but if you add include_docs=true to the URL of your view, you will get the following result:
{ ... "rows": [ { "key": ["Blog Article Title", 0], "value": null, "doc": { "_id": "...", "title": "Blog Article Title", "content": "... blah blah blah ...", "author": "someguy", "type": "post" }, }, { "key": ["Blog Article Title", 1], "value": { "_id": "someguy" }, "doc": { "_id": "someguy", "name": "Some Guy", "email": " someguy@foo.bar ", "type": "author" } } ] }
Now both objects are included in one request. :)
See this article for more information on entity relationships in CouchDB.