MongoDB & Parse Server - Can not query based on geoPoint

136 views Asked by At

Simple Query:

PFQuery *query=[PFQuery queryWithClassName:@"Adventures"];
[query whereKey:@"location" nearGeoPoint:self.userLocation withinMiles:100];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {}];

The self.userLocation is a PFGeoPoint.

I added an index on mongo thanks to this post:

{ "userLocation" : "2d" }

I am pretty sure the error comes from how I am creating the location field in my Adventure class. I am using pymongo to access my MongoDB and using this code to create the location objects:

def createPFGeoPoint():
    for x in Adventures.find():
        if "longitude" in x and "latitude" in x:
            ##x['location']=json.dumps({"__type": "GeoPoint", "coordinates": [x['longitude'], x['latitude']]});
            x['location']=[x['longitude'], x['latitude']];
            ## save is deprecated but insert_one throws an error: duplicate key error collection: database.Adventures 
            Adventures.save(x)

Parse says to create a JSON object like {"__type": "GeoPoint","latitude": 40.0,"longitude": -30.0}. Mongo says to create a JSON object like { type: "Point", coordinates: [ 40, 5 ] }. When trying the above, it comes out as a string type and I'm pretty sure it needs to be an array of the coordinates because:

When I upload a PFGeoPoint using the IOS Parse framework it comes out as an array enter image description here

When saving the location as an array like this [-71.12345, 50.12345] I print it out on the client side and the location object IS recognized as a PFGeoPoint. So I assumed I was creating them correctly.

Finally on the server side I am getting this error:

error: Parse error: MongoError: unknown operator: $maxDistance

Querying just the Adventure class returns results. Querying with just nearGeoPoint: returns nothing but no error. Querying nearGeoPoint: withinMiles: returns an error.

0

There are 0 answers