Skip to content

Instantly share code, notes, and snippets.

@alexshyba
Created November 25, 2015 22:12
Show Gist options
  • Save alexshyba/fac845dc5b6ca61730bc to your computer and use it in GitHub Desktop.
Save alexshyba/fac845dc5b6ca61730bc to your computer and use it in GitHub Desktop.
Mongo: using aggregate to access page event meta data within XDB
db.Interactions.aggregate([
{ "$match": { "StartDateTime": { $gte: ISODate("2015-11-01T00:00:00.000Z"),
$lt: ISODate("2015-11-01T03:00:00.000Z")}}},
{ $project : { Pages : "$Pages" } },
// Un-wind the array's to access filtering
{ "$unwind": "$Pages" },
{ "$unwind": "$Pages.PageEvents" },
// Group results to obtain the matched count per key
{ "$group": {
"_id": "$Pages.PageEvents.Name",
"count": { "$addToSet": "$Pages.PageEvents.Text" }
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment