user1807941
user1807941

Reputation: 43

How can I create a ParseQuery for a field that is either undefined, or contains a particular value?

I want to construct a ParseQuery for some data, and I'm looking to return objects that have a particular field either undefined, or with a particular value. Is this possible, or do I have to find all of the values I don't want it to have, and use whereNotEqualTo or whereNotContainedIn ?

Upvotes: 0

Views: 327

Answers (1)

gio
gio

Reputation: 5020

You need to use Compound Queries

ParseTest is class with Value field. It's String type. Table contains next rows

  • '2'
  • '1'
  • undefined

    ParseQuery<TestParse> queryUndefined = ParseQuery.getQuery(TestParse.class);
    queryUndefined.whereDoesNotExist("Value");
    ParseQuery<TestParse> queryParticualValue = ParseQuery.getQuery(TestParse.class);
    queryParticualValue.whereEqualTo("Value", "2");
    ParseQuery<TestParse> orQuery = ParseQuery.or(Arrays.asList(queryUndefined, queryParticualValue));
    List<TestParse> list = orQuery.find();
    

Result of query will contain '2' and undefined values.

Upvotes: 2

Related Questions