我正在尝试使用 rethinkdb 来存储聊天消息,这里是存储的 json:
{
"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",
}
每个用户可能会发送很多消息,现在我想为每个具有最新 created_at 的唯一 from_user_id 选择一条消息。如何编写重新思考查询?我正在使用 golang rethinkdb 驱动程序。谢谢
最佳答案
我认为您已经解决了这个问题,但这将是实现您想要的结果的组查询。
r.DB("example").Table("messages").Group("from_user_id").Max("created_at").Ungroup()
关于go - Rethinkdb如何使用唯一键进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38869505/