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.
I can't do equalTo('myBoolColumn', false)
, because it doesn't return rows that have an undefined
value for this column.
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.
The documentation suggests using containedIn
instead, but it feels wrong to write a containedIn('myBoolColumn', [false, undefined])
query to achieve the expected result.
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.
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({....});
Since you're checking for whether it's false or undefined, you could also more simply do:
var query = new Parse.Query('YourClass');
query.notEqualTo('myBoolColumn', true);
query.find({...});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With