"Thu Apr 18 18:43:24 +0000 2013"
and this means that filtering or grouping by month, week, day, hour, etc. is going to be a great big pain! Now, there is not yet a way to convert this into real ISODate() type using the aggregation framework but it is possible to compare them meaningfully as dates regardless. Hopefully, soon MongoDB will implement SERVER-4434 and this won't be necessary, but it can still be an educational example of how to parse strings.
Converting or computing a value from any other value is the prevue of the `$project` phase - that's the step in aggregation framework pipeline where we take an incoming document and transform some of its fields into some other fields. We can compute new fields, and that's what we will be doing here.
Original document field: "created_at" : "Thu Apr 18 18:43:24 +0000 2013".
What we would like instead: "createdDate" : "2013-04-18T18:43:24"
Note that we can choose to also create fields which have month, day or hour granularity, as we are not limited to a single new field, we can create multiple new fields.
Our first stage will then be something like: { "$project" : { "realDate" : { ??? }, <otherFields>:1 } }
We need to split the string we're getting as "created_at" into parts we will use to construct a real date. That means separating out the year, month, day and time. We'll ignore time zone for the moment and assume everything is in friendly UTC.
{ "$project" : { "yearStr" : { "$substr" : [ "$created_at", 26, 4 ] } } }
is a way to extract the four digit year from the created_at string.
To get all the interesting fields we would use this projection:
So the conversion looks something like this: