6

on https://parse.com/docs/js_guide#queries-arrays there is an example how to find objects where the key's array value contains each of the elements 2, 3, and 4 with the following:

// Find objects where the array in arrayKey contains all of the elements 2, 3, and 4.
query.containsAll("arrayKey", [2, 3, 4]);

However, I would like to find objects where the key's array value contains at least one (not necessarily all) of the elements 2,3, and 4.

Is that possible?

2
  • Can you make containsAll work? Mine is not working. Commented Feb 6, 2016 at 2:51
  • See selected answer: query.containedIn("arrayKey", [2,3,4]); Note that Parse.com is hutting down... Commented Feb 6, 2016 at 20:27

2 Answers 2

18

I'm not positive, but what happens if you try containedIn?

I think if you pass an array, it checks to see if any are contained.

query.containedIn("arrayKey", [2,3,4]);

I know that if you use equalTo with an array key and a singular value, it checks if the value is in the array and returns TRUE. I think this will do something similar and should work. I think it will check if any value in "arrayKey" is in the passed array. If any key object does, it will return the object.

Sign up to request clarification or add additional context in comments.

5 Comments

can we have two containedIn, for two separate keys, in one query? query.containedIn("Key1", [2,3,4]); query.containedIn("Key2", [7,8,9]);
Yes, if it's an AND query so both would be required to be true. If it's an OR query, you'd have to use sub queries if one or the either can be true.
Thanks for getting back. It's an AND query but why is it that when I add both, I get no objects returned. remove the second one and it works
Are you sure that some objects satisfy your query?
Ahh I was too focused on searching for an error rather than looking at my own. My second containedIn had all the strings.uppercase so it was not matching with what was in the database. Thanks for the help
0

swift 3.0

let Query:PFQuery = PFQuery(className: “className”)
Query.whereKey(“Field Name”, containedIn: array)// [“1”,”2”,”3”];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.