Mongodb Aggregate: Nested totals
I am trying to generate a report from our mongo db that tallies up the
unique visits by country code per referral site. I'd like to use
aggregation as I've heard it is quite fast and performance here is an
issue.
We have an account db that has a cc and last referral site associated with
each account.
{
account:"user123",
CountryCode:"CA",
ReferalSite:"Google",
lastLogin:"someisodate"
}
Conceptually, I can write the javascript in a few minutes.
For each unique vistor in accounts db;
visits[vistor.country_code][vistor.refferal_site]+= 1;
Is this query possible with a db.accounts.aggregate()? Or is a map/reduce
the better way to go about this.
Thanks in advance,
No comments:
Post a Comment