1
votes

How do we find if any element of an array is part of another array in a query?

var followers = []; // Array of Parse User pointers query.howTo("attending", followers); // attending is an array of User Pointers.

That is, the query should match if any one or more of the elements in followers exists in attending.

query.containsAll matches for all the elements. Is there something like query.containsSome ?

1
Have you tried using containedIn? - Natan R.
@NatanR. parseplatform.github.io/Parse-SDK-JS/api/classes/… It is used to compare key with values. I need to compare array with array. - InfinitePrime
Isn't it better in this case using a relation instead of an array of pointers? I think you'll have more flexibility, besides the fact that you can add the relationship in both "sides". Ex.: parse.com/questions/inverse-relationship-support - Natan R.
@NatanR. I will give a look into that. But as of now, is comparing arrays supported in a query? - InfinitePrime
I think that, for now, you should use compound queries, like I'm going to suggest in my answer. - Natan R.

1 Answers

1
votes

I was pretty sure you can query two arrays. Take a look into the docs to check better.

In case it doesn't, you can use compound queries.

For example, generate an array of queries, based on the array of followers. The [forEach] is a better idea in this case, but I'm supposing here a for loop.

var followers = []; //array of users var mainQuery = new Parse.Query(YourOtherObject); //for each one of followers var orQuery = new Parse.Query(YourOtherObject); orQuery.equalTo("attending", follower); mainQuery = Parse.Query.or(mainQuery, orQuery);

This solution might not be performant if your followers areay is too big. But in any case, I still recommend using relations in this case, as you benefit from the inverse, and can get from the users query, where he is present as attending in the other Object.