Created
February 12, 2013 10:30
-
-
Save gsamat/4761441 to your computer and use it in GitHub Desktop.
Find out all reading per hour in Bookmates mongo activity database using map-reduce.
Old mongo, no aggregates :(
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
conn = new Mongo(); | |
db = conn.getDB("publisher_bookmate"); | |
db.getMongo().setSlaveOk(); | |
var mapFunction1 = function() { | |
emit(this.read_at, this.size); | |
}; | |
var reduceFunction1 = function(keyCustId, readcount) { | |
return Array.sum(readcount); | |
}; | |
res= db.getCollection("stats.reading_hourlies").mapReduce( | |
mapFunction1, | |
reduceFunction1, | |
{ | |
out: { inline: 1 }, | |
query: { | |
"read_at": { $gte: ISODate("2013-02-11T00:00:00Z")} | |
} | |
} | |
) | |
//printjson(res) | |
var walk = function(o){ | |
for(var prop in o){ | |
if(o.hasOwnProperty(prop)){ | |
var val = o[prop]; | |
if (prop=="_id" || prop=="value") { print(val); } | |
if(typeof val == 'object'){ | |
walk(val); | |
} | |
} | |
} | |
}; | |
walk(res.results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment