【问题标题】:rethinkdb - hasFields to find all documents with multiple multiple missing conditionsrethinkdb - hasFields 查找具有多个多个缺失条件的所有文档
【发布时间】:2016-10-15 23:26:45
【问题描述】:

我找到了在此 SO 线程 RethinkDB - Find documents with missing field 中查找缺少字段的表中的所有文档的答案,但是我想根据缺少的字段和不同字段中的某个值进行过滤。

我想返回所有缺少字段email 且isCurrent: 值为1 的文档。因此,我想返回所有缺少电子邮件字段的当前客户,以便我可以添加该字段。
rethink 网站上的文档未涵盖此案例。

这是我最好的尝试:

r.db('client').table('basic_info').filter(function (row) {
  return row.hasFields({email: true }).not(),
/*no idea how to add another criteria here (such as .filter({isCurrent:1})*/

  }).filter

【问题讨论】:

    标签: rethinkdb rethinkdb-javascript


    【解决方案1】:

    其实一个filter就可以搞定。而且,它会比您当前的解决方案更快:

    r.db('client').table('basic_info').filter(function (row) {
        return row.hasFields({email: true }).not()
          .and(row.hasFields({isCurrent: true }))
          .and(row("isCurrent").eq(1));
    })
    

    或:

    r.db('client').table('basic_info').filter(function (row) {
        return row.hasFields({email: true }).not()
          .and(row("isCurrent").default(0).eq(1));
    })
    

    【讨论】:

      【解决方案2】:

      我刚刚意识到我可以链接多个.filter 命令。 这对我有用:

      r.db('client').table('basic_info').filter(function (row) {
          return row.hasFields({email: true }).not()
      }).filter({isCurrent: 1}).;
      

      我的下一个任务:将所有这些放入一个数组中,然后批量输入电子邮件地址

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-09
        • 1970-01-01
        • 2015-04-29
        • 2015-06-25
        • 1970-01-01
        相关资源
        最近更新 更多