Rethinkdb根据缩减数据排序组数据

时间:2016-08-10 14:37:21

标签: go rethinkdb

我有一个像这样的json文件:我用它来分组数据并按组排序,我使用的是Golang驱动程序,但它似乎不起作用。 我可以使用" created_at"对分组数据进行排序。在减少里面?在golang尝试了这个,但没有工作。

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

我使用r.db(" chaatz")。table(" message")。group(" from_user_id")。max(" created_at"),这是结果,我可以根据reduciton中的created_at进行排序吗?

[
{
"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 个答案:

没有答案