簡體   English   中英

如何指定我要訂購的字段?

[英]How do I specify which field I am ordering by?

我有一個RQL查詢,如下所示:

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

buildsusers都有一個createdDate字段。 我期望結果按builds表的createdDate排序,但實際上是按照users表的順序獲取它們。

如何指定要使用builds表的createdDate用戶?

在加入 ,你應該有一個包含用戶一個“正確”的對象,就可以進行操作。 就像是:

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

我的問題在RethinkDb docs中得到了明確解釋。 尋找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)

雖然這樣做有效,但我還不完全了解。 完全歡迎任何其他解釋或答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM