Created
December 8, 2014 03:56
-
-
Save wetzler/bf72167d348be7304e97 to your computer and use it in GitHub Desktop.
How to use multiple counts to achieve an OR filter on arrayed values in Keen IO (even though we don't recommend arrays if possible!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example event model | |
// User_Created_Event = { | |
// "full_name": "Macy Bode", | |
// "communities": [6,7,8], | |
// "email": "[email protected]" | |
// }, | |
// Find the number of users in Community 6 or 7 | |
Keen.ready(function() { | |
var countA = new Keen.Query("count", { | |
eventCollection: "User Created", | |
filters: [{ | |
"property_name": "communities", | |
"operator": "eq", | |
"property_value": 6 | |
}] | |
}); | |
var countB = new Keen.Query("count", { | |
eventCollection: "User Created", | |
filters: [{ | |
"property_name": "communities", | |
"operator": "eq", | |
"property_value": 7 | |
}] | |
}); | |
var countAnB = new Keen.Query("count", { | |
eventCollection: "User Created", | |
filters: [{ | |
"property_name": "communities", | |
"operator": "eq", | |
"property_value": 6 | |
}, | |
"property_name": "communities", | |
"operator": "eq", | |
"property_value": 7 | |
}] | |
}); | |
client.run([countA, countB, countAnB], function(response){ | |
// number of users in community 6 or community 7 is the number in each minus those in both | |
var solution = response[0].result + response[1].result - response[2].result | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment