使用rethinkDB显示一周中每一天的数据

时间:2018-09-23 13:30:11

标签: node.js express rethinkdb rethinkdb-javascript rethinkdbdash

使用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"
}
]

要这样

{
  "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": ""
      },

    ]
  }
}

我不知道如何解决它或将其原样写出

1 个答案:

答案 0 :(得分:1)

您可以将group与键名,索引,ReQL或自定义函数一起使用。在您的情况下,应该这样做:

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

然后,在您的回调中,您可以轻松地将此结果转换为所需的结构。