I have Couchbase notification documents stored in below format:
{
"_id":"notification::5403cb1a6c965dcfe9",
"alert":"test data",
"body":{
"created_by":"user_54986e326694f10e511cf",
"description":" reported ",
},
"channels":[
"user_54986e326694f10e511cf",
"user_54986e326694f10e511cp"
],
"notification_type":"new_report",
"seen":true,
"timestamp":"2015-01-06T15:48:25.092Z",
"type":"notification"
}
The JSON document contains channels
array, it is a list of user_id
who subscribe to channels. Problem is I have to emit notification document if chaneel field contain user_id
, if I pass user_id ='user_54986e326694f10e511cf'
pass as key parameter.
Below is my Couchbase view map function but it doesn't return anything
function (doc, meta) {
if(doc.type=='notification' && doc.channels){
for (var user in doc.channels) {
emit(user, {
alert: doc.alert,
body: doc.body,
seen: doc.seen,
timestamp: doc.timestamp
});
}
}
}
I am wondering where i am doing wrong.