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

邮差的信 提交于 2019-12-11 05:44:55

问题


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

回答1:


Actually, you can do it in one filter. And, also, it will be faster than your current solution:

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));
})

or:

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



回答2:


I just realized I can chain multiple .filter commands. Here's what worked for me:

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

My next quest: put all of these into an array and then feed the email addresses in batch



来源:https://stackoverflow.com/questions/40065264/rethinkdb-hasfields-to-find-all-documents-with-multiple-multiple-missing-condi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!