映射降低couchdb中的功能以对同一密钥的值进行分组



我以以下形式有我的couchdb文档:

{
  "_id": "ac4a1c9ec5921b8537fcfe4e450046ab",
  "_rev": "4-4911f4615bcefa6dee88068bc8524930",
  "text": "hello how are you",
  "code": 111
}
{
  "_id": "ac4a1c9ec5921b8537fcfe4e450057ee",
  "_rev": "3-f2c94a551065000ba7d468a5a7b2624a",
  "text": "what is your age",
  "code": 112
}
{
  "_id": "ac4a1c9ec5921b8537fcfe4e45010d36",
  "_rev": "1-9c1b7d02eb0497ca3696f2ccda7df2de",
  "text": "keep it up",
  "code": 112
}

我想编写一个地图减少,以便我可以根据代码

对文本字段进行分组

输出应该看起来像:

key   Text
111   [hello how are you]
112   [what is your age , keep it up]

这很安静,您可以使用以下代码。

视图:

function (doc) {
  emit(doc.code, doc.text);
}

降低

function (keys, values, rereduce) {
  return values.join(",")
}

结果

{"rows":[
{"key":100,"value":"one hundred"},
{"key":123,"value":"hello test,hello world"}
]}

我在Cloudant上对其进行了测试。让我知道couchdb上是否有问题

最新更新