CouchDb视图-键入列表 [英] CouchDb view - key in a list

查看:57
本文介绍了CouchDb视图-键入列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询CouchDB,我有一个特殊的需求:我的查询应返回与此条件相对应的文档的名称字段:id等于或包含在归档的文档(列表)中。
例如,字段输出如下:

I Want to query CouchDB and I have a specific need : my query should return the name field of documents corresponding to this condition : the id is equal or contained in a document filed (a list). For example, the field output is the following :

"output": [
       "doc_s100",
       "doc_s101",
       "doc_s102",
       "doc_s103",
   ],

例如,我要获取其输出字段 doc_s102中包含的所有文档。
我在设计文档中写了一个视图:

I want to get all the documents having in their output field "doc_s102" for example. I wrote a view in a design document :

"backward_by_docid": {
           "map": "function(doc) {if(doc.output) emit(doc.output, doc.name)}"
       }

,但是仅当我在输出字段中具有唯一值时,此视图才有效。
如何解决该查询?

but this view works only when I have a unique value in the output field. How can I resolve this query ?

谢谢!

推荐答案

您必须遍历数组:

  if(doc.output) {
      for (var curOutput in doc.output) {
        emit (doc.output[curOutput],doc.name);
      }
  }

请确保输出始终为数组(至少[])

make sure that output always is an array (at least [])

..,当然使用key = xx代替key = [ xxx]

.. and, of course use key="xx" instead key=["xxx"]

这篇关于CouchDb视图-键入列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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