Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-11118

Add dateToString aggregation operator

    XMLWordPrintable

    Details

    • Backwards Compatibility:
      Minor Change
    • Sprint:
      Server 2.7.4

      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.

      --------
      I'd like to propose an aggregation operator that supports formatting date objects as strings (using the strftime function).

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                4 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: