以下文档存储在CouchDB中
{
{
"_id": "1",
"_rev": "3-2882a4696d580cdef754a93c7e5e77e7",
"comb": [
"4-5",
"4-6",
"5-6"
]
},
{
"_id": "2",
"_rev": "2-1991a898a5457308e3a89253e695cef5",
"comb": [
"4-5",
"5-6"
]
}
}
下面是映射函数
function(doc) {
emit(doc.comb, null);
}
而http://localhost:5984/comb/_design/snp/_view/by_test?key="4-6"
只返回
{"total_rows":2,"offset":0,"rows":[
]}
如何在数组中找到元素?
发布于 2015-01-12 13:29:18
您需要为数组的每个元素调用emit
:
for (var i in doc.comb) {
emit(doc.comb[i], null);
}
然后,查询将找到包含查询中指定的键的梳状数组的所有文档。
https://stackoverflow.com/questions/27902556
复制相似问题