0

我有一份包含以下数据的文件。

文件 1。

{
    "_id": "7d7db310ff3acc857c7f301f67979de5",
    "_rev": "1-3ed97634540c35292155ad40b99cafc1",
    "categories": [
        "Computer",
        "Mobile",
        "Automobile",
        "Plumbing"
    ],
    "location": [
        "19.374636239520235",
        "72.82339096069336"
    ],
    "gender": "male",
    "username": "ayushcshah",
    "password": "sokdncx76483ynxwhakdkxfka37",
    "email": "ayushcshah@gmail.com"
}

文件 2。

{
    "_id": "8c499253bce69b992ebe795906fac3d3",
    "_rev": "1-ce394be6ab3c79111344f026e1a3adcf",
    "categories": [
        "Automobile"
    ],
    "location": [
        "19.387757921807914",
        "72.82626360654831"
    ],
    "gender": "male",
    "username": "smithabc",
    "password": "adsadgq36eygdas2ygduabhs",
    "email": "smithabc@gmail.com"
}

我需要一个VIEW,我可以在其中将密钥作为任何字符串发送,它会找到一个文档,其中类别数组包含搜索字符串,它会向我发送相关用户的电子邮件地址值。

示例:如果我将密钥作为“移动”发送,我将获得受人尊敬的用户名值“ayushcshah@gmail.com”

key":"Mobile","value":"ayushcshah@gmail.com"
key":"Computer","value":"ayushcshah@gmail.com"
key":"Automobile","value":"ayushcshah@gmail.com"
key":"Automobile","value":"smithabc@gmail.com"
key":"Plumbing","value":"ayushcshah@gmail.com"
4

1 回答 1

1

以下地图功能应该足够了:

function (doc) {
  if (!doc.categories) return;
  for (var c in doc.categories) {
    emit(doc.categories[c], doc.email);
  }
}
于 2013-03-30T13:07:52.297 回答