Getting first day of week from week number in mongodb

前端 未结 3 1174
暗喜
暗喜 2021-01-13 14:59

I have collection containing date field. I\'m Grouping records by week and other related fields.

This is my aggregation query:



        
3条回答
  •  太阳男子
    2021-01-13 15:40

    With MongoDB 3.6

    { 
      '$project' : {
        'firstDateOfWeek': {
            '$dateFromString': {
                'dateString': {
                    '$concat': [
                        {
                            '$toString': '$_id.year'
                        }, 
                        '-', 
                        {
                            '$toString': '$_id.week'
                        }
                    ]
                 },
                 'format': "%G-%V"
             }
         }
      }
    }
    

提交回复
热议问题