rethinkdb-hasFields查找具有多个多个缺失条件的所有文档 [英] rethinkdb - hasFields to find all documents with multiple multiple missing conditions
问题描述
我找到了一个答案,可以在此SO线程 RethinkDB-查找缺少字段的文档,但是我想根据丢失的字段和其他字段中的某个值进行过滤.
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.
我想返回所有缺少字段email
并且其isCurrent:
值为1
的文档.因此,我想返回缺少电子邮件字段的所有当前客户,以便我可以添加该字段.
rethink网站上的文档没有涵盖这种情况.
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.
这是我的最佳尝试:
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
中完成它.而且,它将比您当前的解决方案更快:
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));
})
或:
r.db('client').table('basic_info').filter(function (row) {
return row.hasFields({email: true }).not()
.and(row("isCurrent").default(0).eq(1));
})
这篇关于rethinkdb-hasFields查找具有多个多个缺失条件的所有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!