Displaying data for each day of the week with rethinkDB

54 views Asked by At

Displaying data for each day of the week with rethinkDB r.row('time_create').dayOfWeek()

[
{
detail: "no",
order_id: "03",
status: "Delivery",
time_create: "2018-09-23T11:06:30.164Z",
time_success: "2018-09-23T11:06:30.164Z"
}
]

To be like this

{
  "date":
  {
    "Sun": [
      {
        "order_id": "00004568",
        "status": "Delivery",
        "time_create": "09/16/2018 10:09:39",
        "time_success": "09/19/2018 10:39:40",
        "detail": ""
      }
    ],
    "Mon": [
      {
        "order_id": "00004568",
        "status": "Delivery",
        "time_create": "09/17/2018 10:09:39",
        "time_success": "09/19/2018 10:39:40",
        "detail": ""
      },

    ]
  }
}

I do not understand how to fix it or write it out as it is

1

There are 1 answers

3
Stock Overflaw On

You can use group with key names, indexes, ReQL or custom functions. In your case this should do:

r.db('db').table('table')
.getAll(...)
.filter(...)
.group(
  r.row('time_create').dayOfWeek()
)

Then, in your callback, you can easily transform this result into the structure you want.