0

I have a relatively standard Parse query to obtain the nearest items in the 'checkIn' class to an object's location as follows:

var checkInObject = Parse.Object.extend('checkIn');
var query = new Parse.Query(checkInObject);
query.near('location', request.object.get('location'));
query.limit(Parse.User.current().get('limit'));

This works as expected, however can return checkins of the user carrying out the request. To avoid this I add in an additional constraint so my code now looks like this:

var checkInObject = Parse.Object.extend('checkIn');
var query = new Parse.Query(checkInObject);
query.near('location', request.object.get('location'));
query.notEqualTo('user', Parse.User.current());
query.limit(Parse.User.current().get('limit'));

But with this addition I no longer receive any results from the query. How can I add the constraint and still obtain the required results?

  • can you in plain english describe what you want from the query so we can help you construct it ? or you just want so skip current user ? btw notEqualTo is kind of expensive query operator slowing things down ... – PetrV Aug 15 '14 at 09:08
  • The above is an example of the titular issue, which is that any query with both `near` and an additional constraint in it fails. After some discussion with the parse folks it appears that it might be a bug in their product, but in the meantime a generic workaround to a `near` with additional `notEqualTo` constraint would be nice (note that the `notEqualTo` could be `doesNotMatchQuery` for more complex examples) –  Aug 15 '14 at 09:23
  • Can you post a sample of what the raw query data returned looks like? Before any filtering, including columns headers & all columns. – Chris Johnson Aug 21 '14 at 15:29

1 Answers1

0

My suggestion:

Add a string column called "ownerID" and assigned each checkin the value of the objectId of the parse user that created it. Then, you can do this:

var checkInObject = Parse.Object.extend('checkIn');
var query         = new Parse.Query(checkInObject);
query.near('location', request.object.get('location'));
query.limit(Parse.User.current().get('limit'));

query.notEqualTo('ownerID', Parse.User.current().get('objectId')); 

You're also gonna want to make sure that the line where you get 'limit' returns a valid value.

edholmes
  • 60
  • 6
  • Thanks for the response but this isn't the issue; the issue is that combining a `near()` with any other constraint appears to cause the query to fail. –  Aug 18 '14 at 21:13