K
K
kaxa32012020-11-13 16:24:35
MongoDB
kaxa3201, 2020-11-13 16:24:35

How to display the full date when grouping by date?

how can I group, let's say, by month and get the output period: "07/01/2020-07/31/2020" ?

{
    "$group": {
      "_id": {
        "name": "$name",		
        },
        "period": {
            'year': { '$month': "$created_at" },
        },
      },
      "result": {
        "$sum": 1
      }
    }
  },
{
    "$project": {
      '_id': 0,
      "period": '$_id.period',
      "result": "$result"
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question