I save tweets to mongo DB:
twit.stream('statuses/filter', {'track': ['animal']}, function(stream) {
stream.on('data', function(data) {
console.log(util.inspect(data));
data.created_at = new Date(data.created_at);
collectionAnimal.insert(data, function(err, docs) {});
});
});
It's OK.
The tweet time in MongoDB is in format: 2014-04-25 11:45:14 GMT (column created_at)
Now I need group column created_at in hours. I would like to have the result:
hour | count tweets in hour
1 | 28
2 | 26
3 | 32
4 | 42
5 | 36
...
My unsuccessful attempt:
$keys = array('created_at' => true);
$initial = array('count' => 0);
$reduce = "function(doc, prev) { prev.count += 1 }";
$tweetsGroup = $this->collectionAnimal->group( $keys, $initial, $reduce );
But my not able to group by hour.
How to do it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…