I am trying to count the number of specific key-value pairs per UserID and then $bucket these results multiple times by specific conditions such as the country being "US"
I have already tried bucketing by using $match on "country" : "US", "OS" : "iOS" but I only get blank results when trying this and if I remove the $match stage then bucket works but for every single document.
{
iOSUS: [
{
"$match" : {
"_id": {
"country": "$US"
}
}
},{ $bucket : {
groupBy: "$DownloadCount",
boundaries: [ 0, 1, 10, 20, 30, 40, 50, 100, 150, 200, 300, 400, 500],
default: "500+",
output: { count: { $sum: 1 } }
}}
],
// facetName2: [ /* add stages */ ],
// add more facets
}
This is an example of the output I am getting for each document just before this stage. How would I place the "count" inside the "_id" so then the $match function inside $facet would properly separate the buckets?
{
"_id" : {
"UserID" : "106577122",
"country" : "MX",
"OS" : "iOS"
},
"count" : 1289.0
}