CouchDB多级视图地图功能? [英] CouchDB multi level view map function?

查看:67
本文介绍了CouchDB多级视图地图功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太确定该如何称呼我想达到的目标,但会尽可能多地解释它。我正在尝试使用视图从诸如层次结构等相关的单独文档中返回信息。例如,我有这三个文档。

I'm not quite sure what to call what I'm trying to achieve, but will explain it as much as possible. I am trying to use a view to return information from separate documents that are related like a hierarchy. For example, I have these three documents.

{
  "_id" : "line_2c7e12d1",
  "docType" : "Line",
  "lineNumber": 30,
  "pageId" : "page_89bdd679f"
}

{
  "_id" : "page_89bdd679f",
  "docType" : "Page",
  "pageNumber" : 65,
  "bookId" : "book_3684caa2b"
}

{
  "_id" : "book_3684caa2b",
  "docType" : "Book",
  "bookName" : "Some Book Title",
}

我希望能够创建一个视图,该视图允许根据行ID从书中查找信息。多级层次结构。)

And I would like to be able to create a view that allows finding information from about the Book based on the Line id.(multi level hierarchy).

例如,对于查看地图功能来说就是这样。

For example, something like this for the View Map function.

function (doc) {
  if(doc.docType == 'Line'){
    emit([doc._id, 1], doc.lineNumber)
    emit([doc._id, 2], {_id : doc.pageId})
    emit([doc._id, 3], {_id : doc.pageId}.pageNumber)
    emit([doc._id, 4], {_id : {_id : doc.pageId}.bookId})
  }
}

我知道前两条发射线都有效正确,但是后两个不正确。我只是想知道CouchDB中是否可以使用这种功能,或者是否应该以不同的方式构造数据。 (在最低级别包括所有层次结构信息,以便可以向上搜索)。或者如果有人有其他建议。

I know the first two emit lines work correctly, but the second two do not. I am just wondering if this kind of functionality is possible within CouchDB or if I should structure my data differently. (Include all hierarchy information at the lowest level so it can be searched upwards). Or if anyone has any other suggestions.

感谢卡勒姆

推荐答案

您似乎正在尝试将相关文档中的信息包括在视图中。在地图功能中,您只能访问当前文档,而不能在数据库中查询任何其他文档。

It seems that you are trying to include in the view information from related documents. In the map function you only have access to the current doc and you can not query the database for any other document.

您可以按照这种方法获得一种加入功能请参阅

You can obtain a kind of "join" functionality following this approach see.

您的数据结构保持着强大的关系风格,对于面向文档的数据库CouchDB来说,这可能不是最好的方法。

Your data structure is keeping a strong relational flavour that could not be the best approach for CouchDB which is a document oriented database.

这篇关于CouchDB多级视图地图功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆