Boa*_*ler 3 mongodb mongodb-.net-driver
在我的 System ni 中将 MongoDb 升级到 2.6.1 后,有时会出现以下错误:
遗留点超出球形查询范围
错误代码 17444
在这里:https : //github.com/mongodb/mongo/blob/master/src/mongo/db/geo/geoquery.cpp#L73 我可以看到这是由 mongo db 由于某些无效数据引起的。
// The user-provided point can be flat. We need to make sure that it's in bounds.
if (isNearSphere) {
uassert(17444,
"Legacy point is out of bounds for spherical query",
centroid.flatUpgradedToSphere || (SPHERE == centroid.crs));
}
Run Code Online (Sandbox Code Playgroud)
但目前我无法弄清楚为什么以及如何防止它。
我的代码如下所示:
IEnumerable<BsonValue> cids = companyIds.ToBsonValueArray();
return Collection.Find(
Query.And(
Query.In("CompanyId", cids),
Query.Near("Location", location.Geography.Longitude, location.Geography.Latitude, location.Radius / 6371000, true))).ToList();
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
QueryFailure 标志是传统点超出球形查询范围(响应为 {“$err”:“传统点超出球形查询范围”,“代码”:17444})。在 MongoDB.Driver.Internal.MongoReplyMessage
1.ReadFrom(BsonBuffer buffer, IBsonSerializationOptions serializationOptions) at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBinaryReaderSettings readerSettings, IBsonSerializer serializer, IBsonSerializationOptions serializationOptions) at MongoDB.Driver.Operations.QueryOperation1.GetFirstBatch(IConnectionProvider connectionProvider)
您使用的是 MongoDB 2.6.1 或更高版本,因为您正在查看的代码是作为JIRA-13666问题的修复程序添加的。
问题在于,当使用超出范围的旧坐标调用时,某些 $near 查询会使 MongoDB 服务器崩溃。
您可能正在发送超出范围的坐标。在使用最大距离执行 $near 查询时检查经度和纬度的代码部分(geoparser.cpp 中的GeoParser::parsePointWithMaxDistance方法):
bool isValidLngLat(double lng, double lat) {
return lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180;
}
Run Code Online (Sandbox Code Playgroud)
如果坐标超出范围centroid.flatUpgradedToSphere将是错误的,这将导致您收到错误。
您应该将坐标更改为在范围内或将spherical参数设置为 false 以避免出现此错误。
Query.Near("Location", location.Geography.Longitude,
location.Geography.Latitude, location.Radius / 6371000, false)
Run Code Online (Sandbox Code Playgroud)