RethinkDB:合并然后在查询中过滤
RethinkDB: merge and then filter in query
举个例子
r .table('posts')
.get(100)
.merge(function (post) {
return {
comments: r.table('comments').getAll(post('id'),
{index: 'postId'}).coerceTo('array')
}
})
.pluck({"comments": ["id", "created_on"]});
如何将评论进一步过滤为 return 仅特定用户在给定博客 post 上发表的评论。 IE。通过 user_name == 'darth'
获取博客 post 100 和 return 的评论
非常感谢提示
最后完成以下:
r
.table('posts')
.get(100)
.merge(function (post) {
return {
comments: r
.table('comments')
.getAll(post('id'), {index: 'postId'})
.coerceTo('array')
.filter(function (row) {
return r.expr(['darth', 'luke', 'chewey']).contains(row('user_name'));
})
}
})
.pluck({"comments": ["id", "user_name", "created_on"]});
举个例子
r .table('posts')
.get(100)
.merge(function (post) {
return {
comments: r.table('comments').getAll(post('id'),
{index: 'postId'}).coerceTo('array')
}
})
.pluck({"comments": ["id", "created_on"]});
如何将评论进一步过滤为 return 仅特定用户在给定博客 post 上发表的评论。 IE。通过 user_name == 'darth'
获取博客 post 100 和 return 的评论非常感谢提示
最后完成以下:
r
.table('posts')
.get(100)
.merge(function (post) {
return {
comments: r
.table('comments')
.getAll(post('id'), {index: 'postId'})
.coerceTo('array')
.filter(function (row) {
return r.expr(['darth', 'luke', 'chewey']).contains(row('user_name'));
})
}
})
.pluck({"comments": ["id", "user_name", "created_on"]});