rethinkdb - hasFields 查找具有多个多个缺失条件的所有文档

rethinkdb - hasFields to find all documents with multiple multiple missing conditions

我在这个 SO 线程 中找到了在 table 中查找所有缺少字段的文档的答案 ,但是我想根据缺少的字段和不同的特定值进行过滤场地。

我想 return 所有缺少字段 emailisCurrent: 值为 1 的文档。所以,我想 return 所有缺少电子邮件字段的当前客户,以便我可以添加该字段。
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

我刚刚意识到我可以链接多个 .filter 命令。 以下是对我有用的方法:

r.db('client').table('basic_info').filter(function (row) {
    return row.hasFields({email: true }).not()
}).filter({isCurrent: 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));
})