【问题标题】:Rethinkdb join array having subdocumentRethinkdb 加入具有子文档的数组
【发布时间】:2016-08-23 14:56:10
【问题描述】:

当我加入子文档数组时,我没有得到任何结果(也没有错误)。

考虑用户的以下结构

用户表:

{
"email": "email@emaildomain.com",
"id":  "ca433c6a-8cbc-4687-b217-19cabe5fcf63" ,
"image": https://lh4.googleusercontent.com/-44yrW_REeoU/AAEAAAAAAAAI/AAAAAAAAACI/CWvSF3isGRjM/photo.jpg?sz=50, »
"name":  "John Doe" ,
"hobbies": [
{
"id":  "reading" ,
"params": { } ,
"freqency" : "daily"
}
]
}

爱好表:

{
id : "reading",
type : "outdoor"
}

预期结果:

{
"email" : "email@emaildomain.com",
"hobbies" : [{
"id" : "reading",
"params" : {},
"type" : "outdoor",
"frequency" : "daily"
}]

我尝试了以下查询但没有成功。

  r.db('test').table("users")
    .getAll('email@emaildomain.com', {'index' : 'email' })
    .pluck('hobbies')
    .getField('hobbies')
    .eqJoin('id' , r.db('test').table('hobbies'))

我在这里做错了什么?

【问题讨论】:

    标签: rethinkdb rethinkdb-javascript


    【解决方案1】:

    查看How to join tables with a array of IDs

    根据上面的链接,查询是

    r.db('test').table("users")
      .getAll('email@emaildomain.com', {'index' : 'email' })
       .concatMap(function (x) {
         return x("hobbies");
       })
        .eqJoin('id', r.db('test').table('hobbies'))
    

    【讨论】:

      猜你喜欢
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      相关资源
      最近更新 更多