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

$dateToParts should name fields with same names as existing date expression operators

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.0-rc0
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Fully Compatible
    • ALL
    • Repl 2017-10-23

      The $dateToParts expression operator return a document with "isoYear" and "isoWeekYear" fields that confusingly correspond to the return values of the $isoWeekYear and $isoWeek expression operators, respectively. I think we should change the $dateToParts expression operator to use the field names of "isoWeekYear" and "isoWeek" to match the behavior of the existing $isoWeekYear and $isoWeek expression operators.

      Note: We'll want to change $dateFromParts to take the "isoWeekYear" and "isoWeek" field names instead too.

      > db.mycoll.aggregate([{$addFields: {
        parts: {$dateToParts: {date: "$date", iso8601: true}},
        isoWeekYear: {$isoWeekYear: "$date"},
        isoWeek: {$isoWeek: "$date"},
      }}]).toArray()
      [
      	{
      		"_id" : ObjectId("59ce4f35ac2831cef80ed375"),
      		"date" : ISODate("2017-09-29T13:48:37.665Z"),
      		"parts" : {
      			"isoYear" : 2017,
      			"isoWeekYear" : 39,
      			"isoDayOfWeek" : 5,
      			"hour" : 13,
      			"minute" : 48,
      			"second" : 37,
      			"millisecond" : 665
      		},
      		"isoWeekYear" : NumberLong(2017),
      		"isoWeek" : 39
      	}
      ]
      

            Assignee:
            katherine.walker@mongodb.com Katherine Walker (Inactive)
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: