如何指定我按哪个字段排序

How do I specify which field I am ordering by?

本文关键字:字段 排序 何指定      更新时间:2023-09-26

我有一个RQL查询,看起来像这样:

r.table('builds')
    .orderBy(r.desc('createdDate'))
    .limit(100)
    .eqJoin('userId', r.table('users'))
    .run(connection)

buildsusers都有一个createdDate领域。我希望结果按builds表的createdDate排序,但我实际上是按照users表的顺序获取它们的。

如何指定我要使用builds表的createdDate

联接,您应该有一个包含您可以操作的用户的"right"对象。像这样:

r.table('builds')
 .eqJoin('userId', r.table('users'))
 .orderBy(r.desc('right.createdDate'))
 .limit(100)
 .run(connection)

我的问题在 RethinkDb 文档中得到了一些清晰的解释。查找涉及without()的示例

我的查询最终看起来像这样:

r.table('builds')
    .eqJoin('userId', r.table('users'))
    .without({right: 'createdDate'})
    .zip()
    .orderBy(r.desc('createdDate'))
    .limit(100)
    .run(connection)

以下方法似乎也有效,但不建议ordered

r.table('builds')
    .orderBy(r.desc('createdDate'))
    .eqJoin('userId', r.table('users'), {ordered: true})
    .limit(100)
    .run(connection)

虽然这有效,但我并不完全理解。完全欢迎任何其他解释或答案。