MongoDB & Parse Server - 无法基于 geoPoint 进行查询

问题描述

简单查询

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

self.userLocation一个 PFGeoPoint。

多亏了这个post,我在 mongo 上添加一个索引:

{ "userLocation" : "2d" }

我很确定错误来自我在 location 类中创建 Adventure 字段的方式。我正在使用 pymongo 访问我的 MongoDB 并使用此代码创建 location 对象:

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 表示创建一个{"__type": "GeoPoint","latitude": 40.0,"longitude": -30.0} 这样的 JSON 对象。 Mongo 表示创建一个{ type: "Point",coordinates: [ 40,5 ] } 这样的 JSON 对象。尝试上述操作时,它以字符串类型出现,我很确定它需要是坐标数组,因为:

当我使用 IOS Parse 框架上传 PFGeoPoint 时,它会以数组的形式出现

enter image description here

当将 location 保存为这样的数组 [-71.12345,50.12345] 时,我将它打印在客户端,并且位置对象被识别为 PFGeoPoint。所以我认为我正确地创建了它们。

最后在服务器端我收到这个错误

错误:解析错误:MongoError:未知运算符:$maxdistance

查询 Adventure 类返回结果。仅使用 nearGeoPoint: 进行查询不会返回任何错误但不会返回任何错误查询 nearGeoPoint: withinMiles: 返回错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)