How can I access related documents in the map function in CouchDb?

Is it possible to get load values ​​from related documents and emit them as part of a key / value along with values ​​from the current document in CouchDb?

Example:

{Id: 1, Type: Entity, Name: US, Code: 001}
{Id: 2, Type: Entity, Name: Alaska, Code: AL, Parent_Id: 1}
{Id: 3, Type: Entity, Name: California, Code: CAL, Parent_Id: 1}
{Id: 4, Type: Entity, Name: Juneau, Code: C-JUN, Parent_Id: 2}

I would like to read the code, name, etc. from the parent object and the current object and fix them as a key / value in the map function. If the parent has another parent, I would also like to read the values. (Communication in other databases)

+3
source share
1 answer

In map-reduce, if you are emit()an object with _idin it, then this identifier will be the document that you will receive when requested with ?include_docs=true.

So when the card works in California, it will do emit(key, {_id: doc.Parent_id, entity: doc})

?include_docs=true, value.entity , doc .

:

  • .
  • include_docs, _id , emit()

, , . ( Parent_Id , .

+6

All Articles