1

I found an answer for finding all documents in a table with missing fields in this SO thread RethinkDB - Find documents with missing field, however I want to filter according to a missing field AND a certain value in a different field.

I want to return all documents that are missing field email and whose isCurrent: value is 1. So, I want to return all current clients who are missing the email field, so that I can add the field.
The documentation on rethink's site does not cover this case.

Here's my best attempt:

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
4

2 回答 2

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));
})
于 2016-10-16T10:00:14.703 回答
0

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

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

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

于 2016-10-15T23:50:16.517 回答