我有一份包含以下数据的文件。
文件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"
答案 0 :(得分:1)
以下地图功能应该足够了:
function (doc) {
if (!doc.categories) return;
for (var c in doc.categories) {
emit(doc.categories[c], doc.email);
}
}