MongoDB Aggregate Framework - Group by Year

后端 未结 2 541
借酒劲吻你
借酒劲吻你 2020-12-19 04:54

I\'ve been trying to use the aggregate function to group date fields by year:

db.identities.aggregate([
{
    $group : {
        _id : { year : {$year : \"$b         


        
2条回答
  •  悲哀的现实
    2020-12-19 05:50

    This issue is caused by the minimum date not being handled well when aggregated.

    A quick workaround (if possible) is to filter the date, either through the ff:

    • Remove the rows with minimum date (via match / filter)
    • Filter through a certain date (greater than x date)

    Then aggregate.

提交回复
热议问题