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
}
}
]