0

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

Nonzakiz
  • 11
  • 1

1 Answers1

1

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.

Stock Overflaw
  • 3,203
  • 1
  • 13
  • 14
  • console.log [ { group: 1, reduction: [ [Object], [Object], [Object], [Object], [Object] ] } ] i want manager data is example – Nonzakiz Sep 24 '18 at 04:03
  • `group: 1` is the group for monday, and each `[Object]` in `reduction` is a document of your table that was created on monday. You'll have a `reduction` array (i.e. documents) for each `group` (i.e. each day), unless no document was found for that day. Did you read the documentation I linked? – Stock Overflaw Sep 24 '18 at 06:31
  • Cheers mate! ;) – Stock Overflaw Sep 24 '18 at 07:04