Compound query (or) working intermittently

Parse Server Version: 4.5.0
DB: MongoDB v3.6
Parse Client: Parse-Swift SDK 4.2.0

I have a decently large query that uses a few or queries like so:

 if currentUser.sectFilter != 0 && currentUser.religion != nil {
        query = query.where(or(queries: [query.where("religion" == currentUser.religion!), query.where(doesNotExist(key: "religion"))]))
    }

About 70-80% of the time it works perfectly. Other times it lets users through with a different religion in this example. If I do either of those queries separately, they work 100% of the time. Once I put them together as β€œor” I am getting inconsistent results.

Is this an issue with my Parse-Server version, a limitation with Back4App, or am I missing something entirely?

First of all you need to make sure you have an index created for the religion field. In addition to that, I recommend you to use in: ['some religion', null] instead of the or query. It will be way faster. Also, exists and doesNotExist do not have a good performance on mongodb. ne: null and eq: null are better alternatives. In the case, your query continues not working, please open a ticket at back4app.com. The team will be able to help you.

Definitely will give this all a try and report back within the next few days, ty!