如何在搜索对象位于数组中的视图中编写Couchdb的搜索查询?
我有一份包含以下数据的文件 文件1。如何在搜索对象位于数组中的视图中编写Couchdb的搜索查询?,couchdb,Couchdb,我有一份包含以下数据的文件 文件1。 { "_id": "7d7db310ff3acc857c7f301f67979de5", "_rev": "1-3ed97634540c35292155ad40b99cafc1", "categories": [ "Computer", "Mobile", "Automobile", "Plumbing" ], "location": [
{
"_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"
}
{
"_id": "8c499253bce69b992ebe795906fac3d3",
"_rev": "1-ce394be6ab3c79111344f026e1a3adcf",
"categories": [
"Automobile"
],
"location": [
"19.387757921807914",
"72.82626360654831"
],
"gender": "male",
"username": "smithabc",
"password": "adsadgq36eygdas2ygduabhs",
"email": "smithabc@gmail.com"
}
文件2.
{
"_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"
}
{
"_id": "8c499253bce69b992ebe795906fac3d3",
"_rev": "1-ce394be6ab3c79111344f026e1a3adcf",
"categories": [
"Automobile"
],
"location": [
"19.387757921807914",
"72.82626360654831"
],
"gender": "male",
"username": "smithabc",
"password": "adsadgq36eygdas2ygduabhs",
"email": "smithabc@gmail.com"
}
我需要一个视图,在那里我将键作为任何字符串发送,它将找到一个文档,其中类别数组包含搜索字符串,它将向我发送相关用户的电子邮件地址
例如:
如果我将密钥作为“移动”发送,我将获得受人尊敬的用户名作为值”ayushcshah@gmail.com"
以下映射功能应足够:
function (doc) {
if (!doc.categories) return;
for (var c in doc.categories) {
emit(doc.categories[c], doc.email);
}
}