【问题标题】:Displaying data for each day of the week with rethinkDB使用 rethinkDB 显示一周中每一天的数据
【发布时间】:2018-09-23 13:30:10
【问题描述】:

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

    ]
  }
}

我不明白如何修复它或按原样写出来

【问题讨论】:

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


    【解决方案1】:

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

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

    然后,在您的回调中,您可以轻松地将这个结果转换为您想要的结构。

    【讨论】:

    • console.log [ { group: 1, reduction: [ [Object], [Object], [Object], [Object], [Object] ] } ] 我希望经理数据是示例跨度>
    • group: 1 是星期一的组,reduction 中的每个 [Object] 是星期一创建的表的文档。对于每个 group(即每天),您将拥有一个 reduction 数组(即文档),除非当天没有找到任何文档。您是否阅读了我链接的文档?
    • 干杯伙伴! ;)
    猜你喜欢
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2016-03-01
    • 2016-06-13
    • 2015-12-17
    • 1970-01-01
    相关资源
    最近更新 更多