Python geosearch的pymongo.cursor输出速度慢
我在一个充满多边形的集合上执行地理搜索。查询本身相当快,但要获得结果需要3分钟以上。我需要一个解决方案来加速多边形名称的输出 我尝试只包含名称,排除几何体,并且根本不指定任何内容,但都具有相同的效果 输出:Python geosearch的pymongo.cursor输出速度慢,python,python-3.x,mongodb,polygon,Python,Python 3.x,Mongodb,Polygon,我在一个充满多边形的集合上执行地理搜索。查询本身相当快,但要获得结果需要3分钟以上。我需要一个解决方案来加速多边形名称的输出 我尝试只包含名称,排除几何体,并且根本不指定任何内容,但都具有相同的效果 输出: 0:00:00.000061 Result of Query <class 'pymongo.cursor.Cursor'> {'_id': ObjectId('5e70ab3b160bdb5ebde5da7f'), 'name': 'Hessen'} {'_id': Objec
0:00:00.000061
Result of Query
<class 'pymongo.cursor.Cursor'>
{'_id': ObjectId('5e70ab3b160bdb5ebde5da7f'), 'name': 'Hessen'}
{'_id': ObjectId('5e70ab65160bdb5ebde5e0d4'), 'name': 'Hessen/Rheingau'}
{'_id': ObjectId('5e70ab7a160bdb5ebde5e38e'), 'name': 'Hessen'}
{'_id': ObjectId('5e70b707faa4a158f866f6fb'), 'name': 'Frankfurt am Main'}
0:03:11.020437
“2d”索引支持传统的long/lat坐标对,而不是像多边形这样的GeoJSON对象
政府确实支持这些措施。geometry
字段似乎是格式正确的GeoJSON对象,因此您应该能够创建如下索引:
db.polygons.createIndex({"geometry":"2dsphere"})
此索引应支持注释查询。您对该数据有二维索引吗?此查询是集合扫描,因此集合中的每个文档都将从磁盘加载并检查。您第一次报告的时间就是设置光标所花的时间,可能是获得第一批的时间。驱动程序会根据需要自动进行任意多个调用以获得额外的批处理。mogo中的数据如下所示:{“_id”:ObjectId(“5e70ab35160bdb5ebde5d554”),“name”:“摩纳哥”,“geometry”:{“type”:“Polygon”,“坐标”:[[7.414266,43.727287],[7.417669,43.724243],…]}我用:db.polygons.createIndex({“geometry.coordinates”:“2d”})添加了索引,但它并没有加快查询速度索引不起作用,知道吗?>db.polygons.createIndex({geometry:“2dsphere”}){“ok”:0,“errmsg”:“无法提取地理键:{U id:ObjectId('5e70ab77160bdb5ebde5e2b1'),名称:\'Emirat Abu Dhabi\”,几何:{type:\'MultiPolygon\”,坐标:[[54.478299693,24.411246705],
> db.polygons.explain().find({"geometry":{"$geoIntersects":{"$geometry":{ "type" : "Point","coordinates":[8.636274, 50.145938]}}}},{"name":1})
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "GEO.polygons",
"indexFilterSet" : false,
"parsedQuery" : {
"geometry" : {
"$geoIntersects" : {
"$geometry" : {
"type" : "Point",
"coordinates" : [
8.636274,
50.145938
]
}
}
}
},
"queryHash" : "D3B4DDC2",
"planCacheKey" : "45C3B08C",
"winningPlan" : {
"stage" : "PROJECTION_SIMPLE",
"transformBy" : {
"name" : 1
},
"inputStage" : {
"stage" : "COLLSCAN",
"filter" : {
"geometry" : {
"$geoIntersects" : {
"$geometry" : {
"type" : "Point",
"coordinates" : [
8.636274,
50.145938
]
}
}
}
},
"direction" : "forward"
}
},
"rejectedPlans" : [ ]
},
"serverInfo" : {
"host" : "DTO-MB-007.local",
"port" : 27017,
"version" : "4.2.3",
"gitVersion" : "6874650b362138df74be53d366bbefc321ea32d4"
},
"ok" : 1
}
db.polygons.createIndex({"geometry":"2dsphere"})