Reputation: 11753
In cloud code, I made a query using this sort of code:
theMainQuery = new Parse.Query("myClass");
theMainQuery.equalTo("fieldOne", "champion");
theSubQuery = new Parse.Query("myClass");
theSubQuery.equalTo("fieldTwo", "USA");
the2ndSubQuery = new Parse.Query("myClass");
the2ndSubQuery.equalTo("fieldTwo", "BRASIL");
theSubQuery = Parse.Query.or(theSubQuery,the2ndSubQuery);
theMainQuery = Parse.Query.and(theMainQuery,theSubQuery);
In other words I want a query based on this condition:
((fieldOne equals "champion") and ((fieldTwo equals "USA") or (fieldTwo equals "BRASIL")))
In usual C style writing I want to select records matching:
((fieldOne == "champion") && ((fieldTwo == "USA") || (fieldTwo == "BRASIL")))
The problem is that it does not work, I suppose my Parse.Query.and
is wrong. Then how can I get the result I want?
Of course, I would be happy to avoid reformulating the query in this long format:
(((fieldOne == "champion") && (fieldTwo == "USA")) || ((fieldOne == "champion") && (fieldTwo == "BRASIL")))
Upvotes: 0
Views: 111
Reputation: 1632
Okay so what you want to do can be done within one Query object.
I feel what your looking for is 'containedIn'... So you specify the key 'fieldTwo' and pass in an array of values to 'or' with.
So heres what I think it should look like, I implemented this in Objective-C but not javascript. but heres my javascript version
var query = new Parse.Query('myclass');
query.equalTo('fieldOne', 'champion');
query.containedIn('fieldTwo', ['USA', 'Brazil']);
query.find();
I hope this was what your looking for... By the way, I was able to find this in the docs, https://parse.com/docs/js_guide#queries. There docs are very helpful but sometimes doesn't help me :P
Upvotes: 1