[英]How to query for an element in an array
以下文檔存儲在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":[
]}
如何在數組中找到一個元素?
您將需要為數組的每個元素調用emit
:
for (var i in doc.comb) {
emit(doc.comb[i], null);
}
然后,您的查詢將找到所有包含梳狀數組的文檔,其中包含查詢中指定的鍵。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.