[SERVER-11118] Add dateToString aggregation operator Created: 10/Oct/13 Updated: 08/May/15 Resolved: 24/Jul/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | 2.7.4 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Alon Horev | Assignee: | Adam Midvidy |
| Resolution: | Done | Votes: | 4 |
| Labels: | community-team | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Backwards Compatibility: | Minor Change | ||||||||||||||||||||||||
| Sprint: | Server 2.7.4 | ||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||
| Description |
|
Implement a $dateToString aggregation operator. e.g. : $dateToString: {format: "<format string>", date: "<$field>"}
Modifiers should be mostly similar to strftime, but with the addition of milliseconds. All units should be zero-padded to the maximum number of digits for that unit. -------- This comes very handy when working with time-series data. For example: if you want to aggregate documents by a specific hour, you'd have to do this: {$group: {_id: {year: {$year: '$date'}, month: {$month: '$date'}, day: {'$dayOfMonth': '$date'}, hour: {$hour: '$date'}}}} Here's how you can do it with dateFormat: {$group: {_id: {$dateFormat: ['$date', '%Y-%m-%d %H']}}} In addition to the shorter syntax, the results look much nicer (-: I've already implemented the feature and the tests (I'll add a link after the ticket is created). This is my first contribution to the MongoDB server code. I'll open a pull request referencing this issue. Please tell me if I'm doing anything wrong. |
| Comments |
| Comment by Githook User [ 07/Oct/14 ] |
|
Author: {u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}Message: |
| Comment by Githook User [ 24/Jul/14 ] |
|
Author: {u'username': u'amidvidy', u'name': u'Adam Midvidy', u'email': u'amidvidy@gmail.com'}Message: Signed-off-by: Eric Milkie <milkie@10gen.com> |
| Comment by Githook User [ 24/Jul/14 ] |
|
Author: {u'username': u'kaloianm', u'name': u'Kaloian Manassiev', u'email': u'kaloian.manassiev@mongodb.com'}Message: |
| Comment by Githook User [ 24/Jul/14 ] |
|
Author: {u'username': u'amidvidy', u'name': u'Adam Midvidy', u'email': u'amidvidy@gmail.com'}Message: Signed-off-by: Matt Kangas <matt.kangas@mongodb.com> |
| Comment by Asya Kamsky [ 12/Oct/13 ] |
|
While translating date to string is useful, I think truncating to certain time resolution is a useful functionality by itself - plus it would allow hourly aggregations while maintaining the correct type. Currently it's possible by using date math and subtracting appropriate number of milliseconds from date to truncate it down to an hour (or any preferred) resolution... Maybe that's a separate operator request though - but it seems like a better method to get to hourly granularity of time than turning into a string. |
| Comment by Alon Horev [ 10/Oct/13 ] |
|
Perhaps boost's implementation of date_time is portable enough: http://www.boost.org/doc/libs/1_54_0/doc/html/date_time/date_time_io.html#date_time.format_flags |
| Comment by Mathias Stearn [ 10/Oct/13 ] |
|
One thing to consider is that strftime is full of system-specific extensions which makes it hard to offer as our interface. Additionally none of the system implementations of strftime include milliseconds although ours would have to since BSON Dates have ms resolution. We will probably have to do a from-scratch implementation of strftime-like functionality after deciding on our desired spec to do this properly. |
| Comment by Alon Horev [ 10/Oct/13 ] |
|
Pull request: https://github.com/alonho/mongo/tree/SERVER-11118 |