Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query.withinMiles() will not work while query.near() works fine #2075

Closed
Siraris opened this issue Jun 16, 2016 · 4 comments
Closed

query.withinMiles() will not work while query.near() works fine #2075

Siraris opened this issue Jun 16, 2016 · 4 comments

Comments

@Siraris
Copy link

Siraris commented Jun 16, 2016

I've been trying, to no avail, to get the withinMiles query method to work. From what I can tell, withinMiles calls withinRadians calls near, and the only difference is the $maxDistance property is applied to the query. Below are the methods I'm using for both the withinMiles method and the near method:

query.withinMiles('currentLocation',
      new Parse.GeoPoint(-73.96939568075399, 40.83514669005315), 
      maxDistance
  );

  query.near('currentLocation',
    new Parse.GeoPoint(-73.96939568075399, 40.83514669005315));

Near runs and returns many objects from the database. withinMiles runs and returns an empty array. As you can see, at face value, it's the exact same method call, with the exact same properties, other than the maxDistance argument for withinMiles. maxDistance, for reference, is a Number value as required by the API.

I find it hard to believe that this is a bug, but from everything I can tell, it is. Any help would be appreciated.

@drew-gross
Copy link
Contributor

We have lots of passing test cases that cover these features. Can you post some code that reliably reproduces your issue, including the code that creates the data? Ideally as a test case we can add to our test suite.

@Siraris
Copy link
Author

Siraris commented Jun 16, 2016

This is the exact code that I'm using. Do you see something wrong that I'm doing?

Parse.Cloud.define("minimumUsersForAccess", function(request, response){
  if (!request.user) {
    response.error("Must be signed in to call this Cloud Function.")
    return;
  }

  // Max Distance to search should either be set by request, or default to 20 miles
  var maxDistance = (request.params.maxDistance) 
    ? request.params.maxDistance : 20,
    query = new Parse.Query(Parse.User);

// THIS DOES NOT WORK
  query.withinMiles('currentLocation',
      new Parse.GeoPoint(-73.96939568075399, 40.83514669005315), 
      maxDistance
  );

// THIS WORKS
  query.near('currentLocation',
    new Parse.GeoPoint(-73.96939568075399, 40.83514669005315));

  query.find({
    success: function(users) {
      // return true if more than 50 users returned, otherwise not enough
      // users for access
      console.log(users);
      response.success((users.length >= 50) ? true : false);
    }
  });
});

I don't have access to the code that creates the data unfortunately. Regardless, this is the shape of the location data in mongo:

"currentLocation": [
-71.1670245290879,
42.33827739107621
]

@drew-gross
Copy link
Contributor

We have multiple tests for the withinMiles feature in the ParseGeoPoint.spec.js file that all pass. Without a complete set of steps to reproduce this issue, it's very difficult for us to help.

If you aren't using mongodb version 3.0.8, try switching to that version, as other versions have had some issues with geo queries.

@hramos
Copy link
Contributor

hramos commented Jun 24, 2016

We are closing this issue due to a lack of sufficient information.

Please refer to this issue for an example of a great bug report.

You may use Server Fault for questions about managing Parse Server.

For code-level and/or implementation-related questions or technical support, please refer to Stack Overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants