【问题标题】:Accessing nested fields with Rethinkdb使用 Rethinkdb 访问嵌套字段
【发布时间】:2019-02-22 12:18:46
【问题描述】:

所以我有一个看起来像这样的结果

"data": {
  "randomkeyllasdkjflk": {
     "name": "John Doe"
  },
  "anotherrandomkeyadf": {
     "name": "Mona Lee"
  }
}

我想访问该名称。

这是我尝试过的:

r.table('users').filter(function (doc) {

      return doc('data').coerceTo('array').map(function(ref) {
        return ref('name')
      }).contains("John")

    });

但是会产生一个错误,上面写着:

e: 不能对非对象非序列执行括号 "randomkeyllasdkjflk"

【问题讨论】:

    标签: rethinkdb rethinkdb-javascript


    【解决方案1】:

    使用这个:

    r.table('users').filter(function (doc) {
    
      return doc('data').keys().map(function(ref) {
        return doc('data')(ref)('name')
      }).contains("John")
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 2016-09-08
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多