W
W
WAYNEDEV2020-05-09 22:48:19
Node.js
WAYNEDEV, 2020-05-09 22:48:19

How to return grouped data by date node + mongoose?

Hello!
There is a User model, it stores data:

{
  name: 'user',
  history: [
    { date: 01, val: 2},
    { date: 01, val: 3},
    { date: 02, val: 2}
  ]
}


Задача заключается в выдаче res.json в формате:
{
  history: [
    {
      title: 01,
      data: [
        { date: 01, val: 2},
        { date: 01, val: 3}
      ]
    },
    {
      title: 02,
      data: [
        { date: 02, val: 2},
      ]
    },
  ]
}


That is, as a result, give out grouped values ​​​​by history.
How to do it correctly, given that there will be pagination?

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