0

I have following collection in mongodb

[
      {
        "createdAt": 1596700221742,
        "id": "5f2bb63da9babddd420d0fa6",
        "quoteId": "SBA0005",
        "commission": 0,
      },
      {
        "createdAt": 1596699868976,
        "id": "5f2bb4dcbcf1acdbb64137d0",
        "quoteId": "SBA0004",
        "commission": 0,
      }]

How can we group this by date?

Prajwal
  • 319
  • 4
  • 10

1 Answers1

0

Try this one:

db.collection.aggregate([
  {
    $group: {
      _id: {
        y: { $year: { $toDate: "$createdAt" }},
        m: { $month: { $toDate: "$createdAt" }},
        d: { $dayOfMonth: { $toDate: "$createdAt" }}
      }
    }
  }
])

Most likely it will not give the result you are looking for. However, based on your input that's all what ca be provided as solution.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110