Hello,
I use couchbase view to retrieve user that need to get a push notification on a mobile game.
The user receive push notification when I has not been offline for 3,7,14 or 21 days, based on a field “lastUpdate” stored in a json document.
for that I implemented the following map :
{
"map" : "function (doc, meta){ if(doc.type == 'user') { if (doc.lastUpdate && doc.token && doc.notificationsEnabled) { if (doc.token != '' && doc.notificationsEnabled == true) { emit(dateToArray(doc.lastUpdate),[meta.id,doc.retentionPN]); } }}}"
}
The results are retrieved using the following node.js code
var endDate = moment().utc().add(delay,"seconds");
var startDate = moment("2015-05-01 00:00:00");
var endDateArray = endDate.toArray().slice(0,6); // couchbase and moment dont use same month/day start index
var startDateArray = startDate.toArray().slice(0,6);
endDateArray[1]++;
startDateArray[1]++;
var query = ViewQuery.from('myview','withtoken_bydate').range(startDateArray, endDateArray, true).limit(100);
This works fine but I would like to check at the map level if one of the following subkey from the user profile is true, check d3 in case I check the d+3 interval, d7 in case I check the d+7 interval…
"retentionPN": {"d3": false,"d7": false,"d14": false,"d21": false}
Can do it as the viewQuery level , like for instance the following pseudo code
var query = ViewQuery.from('myview','withtoken_bydate').range(startDateArray, endDateArray, true).checkField("retention.d3",false).limit(100);