问题描述
我正在使用解析 sdk,当我尝试搜索 nearGeoPoint 时,我得到 p>
I'm using parse sdk and when i try to search nearGeoPoint I get
2016-05-01 18:33:17.275 Partee[2557:1416403] [Error]: internal error (Code: 1, Version: 1.13.0)
2016-05-01 18:33:17.275 Partee[2557:1416403] [Error]: Network connection failed. Making attempt 1 after sleeping for 1.965591 seconds.
我使用的代码是
let query = PFQuery(className: "Parties")
let myLocation = currentuser?.objectForKey("location") as! PFGeoPoint
query.whereKey("location", nearGeoPoint: myLocation, withinKilometers: 100)
query.findObjectsInBackgroundWithBlock({ (objects, error) in
if error == nil {
print("\(objects?.count) searches found")
}
}
})
where currentuser 有location"作为他的当前位置已经保存,所以我试图搜索该用户 100 公里附近的派对,但我不断收到错误,如果我评论 nearGeoPoint它工作得很好.
where currentuser has "location" as his current location already saved, so I'm trying to search parties near 100 kilometer of that user but I keep getting that error, if i comment nearGeoPoint line then it works perfectly fine.
推荐答案
我在 mLab 上从 Parse 迁移到 MongoDB 时遇到了这个问题.
I had this issue on migrating from Parse to MongoDB on mLab.
您需要向 GeoPoint 字段添加二维索引.如果您使用的是 MongoDB,请执行以下任一操作.
You need to add a 2d index to your GeoPoint field. If you are using MongoDB, do either of the following.
Mongo Shell:
db.test.createIndex({ "userLocation": "2d" })
例如.其中test"是您的集合名称,userLocation"是您在该集合中的 GeoPoint 字段的名称.
Eg. Where 'test' is your collection name and 'userLocation' is the name of your GeoPoint field inside this collection.
mLab 用户界面仪表板:
转到您的数据库.转到具有导致问题的 GeoPoint 字段的集合.转到顶部栏中的索引".选择添加索引"输入,例如:
Go to your database.Go to the Collection that has the GeoPoint field causing the problem. Go to 'Indexes' on the top bar. Select 'Add Index' Input for example:
{ "userLocation" : "2d" }
例如.其中userLocation"是此集合中您的 GeoPoint 字段的名称.
Eg. Where 'userLocation' is the name of your GeoPoint field inside this collection.
那应该可以解决它.
这篇关于搜索 NearGeoPoint 时出现内部错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!