I have a simple database structure for tracking a users time on a website. The session_time entry is accumulative. i.e The first session_time entry when you search by session_id with always be 0 last entry will always be the total session time
I require a MongoDB mapreduce function/query that can collect the total, hourly, daily, monthly etc session time for a user_id within a date range using created_at.
The structure of the data is like:
{
_id "4f2d1122ae06ff0003000002"
user_id "d77c8001-adc4-49c6-9e83-d58208e78ebd"
session_id "1e49ab89c2f634b4"
session_time 0
created_at 2012-02-04 11:06:10 UTC
updated_at 2012-02-04 11:06:10 UTC
},
{
_id "4f2d1141ae06ff0003000004"
user_id "d77c8001-adc4-49c6-9e83-d58208e78ebd"
session_id "1e49ab89c2f634b4"
session_time 31
created_at 2012-02-04 11:06:41 UTC
updated_at 2012-02-04 11:06:41 UTC
},
{
_id "4f2d1163ae06ff0003000006"
user_id "d77c8001-adc4-49c6-9e83-d58208e78ebd"
session_id "1e49ab89c2f634b4"
session_time 61
created_at 2012-02-04 11:07:15 UTC
updated_at 2012-02-04 11:07:15 UTC
}