How to execute an effective boolean query "false" or "undefined" in Parse?

I have a Boolean column in one of my Parse entities, and I want to query for all rows that have this column explicitly set to false , or left to the default value undefined .

I cannot do equalTo('myBoolColumn', false) because it does not return rows with an undefined value for this column.

I would prefer not to do notEqualTo('myBoolColumn', true) , because the analysis documentation says that notEqualTo queries are inefficient, t use indexes.

The documentation suggests using containedIn instead, but it's wrong to write a containedIn('myBoolColumn', [false, undefined]) query containedIn('myBoolColumn', [false, undefined]) to achieve the expected result.

It seems that notEqualTo logical queries can still be indexed, but I have not found an authoritative source that confirms this, and I do not know how to check whether this query uses an index or not.

So which one should I use: notEqualTo('myBoolColumn', true) or containedIn('myBoolColumn', [false, undefined]) ?

+5
source share
2 answers

You want to combine the two queries as follows:

 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({....}); 
+6
source

Since you are checking to see if it is false or undefined, you can also just do the following:

 var query = new Parse.Query('YourClass'); query.notEqualTo('myBoolColumn', true); query.find({...}); 
+2
source

All Articles