我正在以以下格式存储 couchbase 报告文档:
{
"agree_allowed":true,
"assigned_by":"",
"assigned_to":"",
"closed":[
],
"comments_allowed":true,
"details":"Test",
"email":"",
"status":"In Progress",
"subscribed":{
"user_cfd29b81f0263a380507":true,
"user_cfd29b81f0263a380508":true,
"user_cfd29b81f0263a380509":true,
"user_cfd29b81f0263a3805010":true
},
"summary":"Test",
"time_open":0,
"timestamp":"2015-07-17T15:34:30.864Z",
"type":"report",
"user_id":"user_cfd29b81f0263a380507",
"username":"test17"
}
json 包含订阅的字段,它是关注报告的 user_id 列表。问题是如果订阅字段包含 user_id,我必须发出报告文档,如果我通过user_id ='user_cfd29b81f0263a380507 ' 作为关键参数传递。我想知道如何使用user_id在视图中进行比较
这是我写的代码:-
function map(doc, meta) {
if (doc.type == 'report' && doc.subscribed) {
for (var user_id in doc.subscribed) {
emit(doc.user_id, doc);
}
}
}
但它没有返回预期的结果。任何人都可以帮忙。