我在rethinkdb中有很多字段和项目的表,我希望得到这个表的所有数据但是在项目的情况下我只想要最后2个记录:查看结果和查询
{
"adm": "1" ,
"chat": "user_273_1" ,
"id": "09ce2adc-9d49-4830-9fb6-fb7159f92d08" ,
"msg": [
{
"date": "2016-07-20T01:43:06.302Z" ,
"id": "4e1d85e0-4e1b-11e6-bb9f-2bb985f41f5d" ,
"msg": "sgzsrgz" ,
"nick": "SonickSeven" ,
"user": "1"
} ,
{
"date": "2016-07-20T01:43:08.832Z" ,
"id": "4f9f9200-4e1b-11e6-bb9f-2bb985f41f5d" ,
"msg": "egser" ,
"nick": "SonickSeven" ,
"user": "1"
} ,
{
"date": "2016-07-20T01:43:55.233Z" ,
"id": "6b47cd10-4e1b-11e6-bb9f-2bb985f41f5d" ,
"msg": "sergse" ,
"nick": "SonickSeven" ,
"user": "1"
}
],
"optChat": [
{
"height": 0 ,
"minizar": true ,
"position": false ,
"user": "1" ,
"user2": "273" ,
"width": 0 ,
"x": 0 ,
"y": 0
}
]
}
并显示:
{
"adm": "1" ,
"chat": "user_273_1" ,
"id": "09ce2adc-9d49-4830-9fb6-fb7159f92d08" ,
"msg": [
{
"date": "2016-07-20T01:43:08.832Z" ,
"id": "4f9f9200-4e1b-11e6-bb9f-2bb985f41f5d" ,
"msg": "egser" ,
"nick": "SonickSeven" ,
"user": "1"
} ,
{
"date": "2016-07-20T01:43:55.233Z" ,
"id": "6b47cd10-4e1b-11e6-bb9f-2bb985f41f5d" ,
"msg": "sergse" ,
"nick": "SonickSeven" ,
"user": "1"
}
],
"optChat": [
{
"height": 0 ,
"minizar": true ,
"position": false ,
"user": "1" ,
"user2": "273" ,
"width": 0 ,
"x": 0 ,
"y": 0
}
]
}
但我想只显示子字段中的最后两项:" msg"显示一些喜欢它:
{{1}}
我怎么可能,我搜索过这个在互联网上解决它但我什么都不匹配
答案 0 :(得分:0)
您可以在查询结尾添加.merge(function(row) { return {msg: row('msg').slice(-2)}; })
。