insane.bot
insane.bot

Reputation: 193

ParseQuery with whereNear() ignores others conditions

The query below is utterly ignoring the second condition (the filter, that is a string field).

But when the whereNear() condition is commented, the filter is applied.

Does whereNear() condition cause to ignore others conditions? If yes, what would be the correct approach in this case?

ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
query.whereNear("location", new ParseGeoPoint(latitude, longitude));
query.whereEqualTo("filter", filter);
query.orderByDescending("createdAt");
List<ParseObject> objects = query.find()

Upvotes: 0

Views: 81

Answers (2)

Msp
Msp

Reputation: 2493

From Parse documentation,

If an additional orderByAscending()/orderByDescending() constraint is applied with whereNear(), it will take precedence over the distance ordering.

So, whereNear() won't override orderByDescending(). It is the other way around. Also,

Using the whereNear() constraint will also limit results to within 100 miles.

If there are no points nearby given point within 100 miles which satisfy the second filter. I think that's why you are getting unexpected results.

Upvotes: 1

Sudip Podder
Sudip Podder

Reputation: 838

whereNear() shouldn't be the reason for whereEqualTo() being ignored (I have an app with same condition as yours and it works fine). You rather give your focus on orderByDescending(), because it takes precedence over whereNear().

Note: As per parse documentation, an additional orderByAscending()/orderByDescending() constraint is applied, it will take precedence over the distance ordering.

Upvotes: 1

Related Questions