dongxian1699 2016-08-10 14:37
浏览 51

Rethinkdb根据归约数据对组数据进行排序

I have a json file like this: which I used to group data and sort after group, and I am using golang driver but it seems not work. Can I sort the grouped data with the "created_at" inside the reduction? Tried this one in golang but no work.

r.DB(database).Table(table).Group("from_user_id").Max("created_at").
Ungroup().OrderBy(r.Desc("created_at")).Run(session)

{
"body":  "Hi" ,
"created_at": Wed Aug 10 2016 05:39:57 GMT+00:00 ,
"from_user_id":  "user11" ,    
"send_direction":  "client" ,
"to_user_id":  "user10",
}

I group with r.db("chaatz").table("message").group("from_user_id").max("created_at"), and here is the result, can I sort according the created_at in reduciton?

[
{
"group": "0fa92543-59c9-4896-97a2-c703da32c77c" ,
"reduction": {
"avatar": 
"body": "Hi" ,
"created_at": Wed Aug 10 2016 11:22:50 GMT+00:00 ,
"from_user_id": "0fa92543-59c9-4896-97a2-c703da32c77c" ,
"id": "c4b20a64-c665-447c-a17b-67c0adfb7176" ,
"msg_id": "09058ed8-853b-4057-8e09-a7c6ee4be1f7" ,
"send_direction": "client" ,
"to_user_id": "01c171cd-1be6-4b2b-8448-79a87c8f06b6" ,
"updated_at": Wed Aug 10 2016 11:22:50 GMT+00:00
}
} ,
{
"group": "user123" ,
"reduction": {
"avatar": 
"body": "Hi" ,
"created_at": Wed Aug 10 2016 13:23:21 GMT+00:00 ,
"from_user_id": "user123" ,
"id": "954ac289-7490-4c08-8859-e222148f86b2" ,
"msg_id": "c5138387-cba4-42b7-b0ba-1f479433ce88" ,
"send_direction": "client" ,
"to_user_id": "01c171cd-1be6-4b2b-8448-79a87c8f06b6" ,
"updated_at": Wed Aug 10 2016 13:23:21 GMT+00:00
}
}
]
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看