mongodb - Order tweet according to created_at field -
when using twitter stream api retrieve tweets, each tweet downloaded its
created_at
field, string
field in format, e.g.,
mon sep 01 00:00:00 +0000 2014
i stored these tweets in mongodb database. order tweets according date, if ask mongodb order them based on created_at
field, string:
db.collection.find({},{created_at:1}).sort({created_at:1})
the dates ordered according lexicographic ordering, not want.
how can modify query order them based on date , not on string? tried isodate
objects, since field string, not work.
thanks.
by using mapreduce:
db.rawtweets.mapreduce( // map function() { emit( // "thu jul 17 03:21:42 +0000 2014" new date(date.parse(this.created_at.replace(/(\+\s+) (.*)/, '$2 $1'))).tolocaledatestring(), 1 ); }, // reduce function(key, values) { return array.sum(values) }, { query: {}, out: "rawtweetscount" } )
Comments
Post a Comment