Query related to number of items in a ParseRelation (relation empty or not)


I’m facing an issue which i think it is simple to resolve but i can’t find a solution.

I have a collection named “Event” with a relation field inside called “attendees” of type _User.

I would like to query Events with at least one attendee or events that are not empty.

I’ve tried containedIn, matchesQuery, exists, matchesKeyInQuery… but it always returns 0 results.

Is there any way to build this query ? Do I have to query each time attendees ? I would like to not do post processing query


Could you share the code of what you’ve tried?


This is what I tried:

const query = new Parse.Query('Events')
query.notEqualTo('attendees', [])
const query = new Parse.Query('Events')
const query = new Parse.Query('Events')
const innerQuery = new Parse.Query('_User')

query.matchesQuery('attendees', innerQuery)

1st one → crash but I understand because it is not a pointer or primitive value
2nd one → doesn’t work
3rd → the matchesQuery is always returning 0 results

Thank you

I believe that the third way should work but not with a good performance. I’d probably create a trigger or cloud code function to maintain a counter of attendees in the Events class. Or use aggregate: JavaScript Developers Guide | Parse