Couchdb join two documents using key

a 夏天 提交于 2019-11-28 01:30:26
Daniel

To simulate joins you have to output a doc with an _id in it, the value of the _id needs to point to an actual _id of a document. Then you can make use of include_docs=true to pull in the related documents. Example with many-to-many here: http://danielwertheim.se/couchdb-many-to-many-relations/

If this is not applicable, you can make a two step manual join by first returning custom keys. Then make a second query against the all documents view, with multiple keys specified.

It is much late but For such kind of tree structure, documents should be kept separately such as

{
  id="firstDoc",
  type="rootLevel"
}
{
  id="secondDoc",
  type="firstLevel"
  parent="firstDoc"
}
{
  id="thirdDoc",
  type="firstLevel",
  parent="firstDoc"
}

Now different levels can be joined using the Map Reduce function, Make sure that you will use it in proper way, Also use Logging so that you will be able to know in which sequence map/reduce function are being called by CouchDB.

Further, map Function should only be used for emitting the required document suppose if you want to to emit your level3 then in emit's value part, root.level1.level2.level3 should be there.

For more detail about the join you can refer

CouchDB Join using Views (map/reduce)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!