问题描述
我在一个Parse实体上有一个Boolean
列,我想查询所有具有明确设置为false
或保留为其默认undefined
值的列的行.
I have a Boolean
column on one of my Parse entities, and I want to query for all rows that have this column either explicitly set to false
, or left to its default undefined
value.
我无法执行equalTo('myBoolColumn', false)
,因为它不会返回该列具有undefined
值的行.
I can't do equalTo('myBoolColumn', false)
, because it doesn't return rows that have an undefined
value for this column.
我宁愿不使用notEqualTo('myBoolColumn', true)
,因为分析文档指出,notEqualTo
查询效率不高,因为它们无法利用索引.
I'd rather not do a notEqualTo('myBoolColumn', true)
, because the Parse documentation states that notEqualTo
queries are not efficient because they can't take advantage of indexes.
文档建议改用containedIn
,但是编写containedIn('myBoolColumn', [false, undefined])
查询以实现预期结果感觉很错误.
The documentation suggests using containedIn
instead, but it feels wrong to write a containedIn('myBoolColumn', [false, undefined])
query to achieve the expected result.
似乎notEqualTo
布尔查询仍然可以建立索引,但是我没有找到可以证实这一点的权威信息,而且我不知道如何测试该查询是否使用索引.
It seems like notEqualTo
boolean queries could still be indexed, but I did not find an authoritative source that confirms this, and I don't know how to test if this query uses an index or not.
那么我应该使用哪个:notEqualTo('myBoolColumn', true)
或containedIn('myBoolColumn', [false, undefined])
?
So which one should I use: notEqualTo('myBoolColumn', true)
or containedIn('myBoolColumn', [false, undefined])
?
推荐答案
您想像这样组合两个查询:
You want to combine two queries like so:
var falseQuery = new Parse.Query('YourClass');
falseQuery.equalTo('myBoolColumn', false);
var undefinedQuery = new Parse.Query('YourClass');
undefinedQuery.doesNotExist('myBoolColumn');
//this is the query you should run
var query = Parse.Query.or(falseQuery, undefinedQuery);
query.find({....});
这篇关于如何执行有效的布尔“假或未定义"布尔值?在解析查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!