如何解决Pymongo地理空间索引无法正常工作,地理查询无法找到结果
import pprint
pprint.pprint(collection.find_one())
文档:
{'_id': ObjectId('5ddc4ccd7d47db47b817e3fc'),'geometry': {'coordinates': [-76.47704,44.23262],'type': 'Point'},'properties': {'BaseDateTime': '2017-01-01T00:01:10','COG': -49.6,'Cargo': '60','Draft': '2.3','heading': 100.0,'MMSI': 316013007,'SOG': -0.1,'Status': 'under way using engine','Vessel Info': {'CallSign': 'VA3418','IMO': 'IMO7423079','Length': 62.49,'VesselName': 'WOLFE ISLANDER III','VesselType': 'WOLFE ISLANDER III','Width': 20.27}},'type': 'Feature'}
我创建了GeoSpatial索引:
avail_indexes = collection.list_indexes()
for idx in avail_indexes:
print(idx)
第二个索引是地理空间索引:
SON([('v',2),('key',SON([('_id',1)])),('name','_id_'),('ns','testing_data.tesing_data')])
SON([('v',SON([('geometry.coordinates','2dsphere')])),'location'),('background',False),('2dsphereIndexVersion',3),'testing_data.tesing_data')])
我的问题是我无法使用地理空间索引来找到某个点附近的文档。没有文件退回:
query = {'geometry': {'coordinates': { "$near": [-76.47704,44.23262]}}}
p = collection.find(query).explain()
p['executionStats']
没有退回文件。
{'executionSuccess': True,'nReturned': 0,'executionTimeMillis': 18,'totalKeysexamined': 0,'totalDocsexamined': 39610,'executionStages': {'stage': 'COLLSCAN','filter': {'geometry': {'$eq': {'coordinates': {'$near': [-76.47704,44.23262]}}}},'executionTimeMillisEstimate': 0,'works': 39612,'advanced': 0,'needTime': 39611,'needYield': 0,'saveState': 309,'restoreState': 309,'iSEOF': 1,'direction': 'forward','docsexamined': 39610},'allPlansExecution': []}
但是我可以确保附近有很多地方:
query = {'geometry': {'type': 'Point','coordinates': [-76.47704,44.23262]}}
p = collection.find(query).explain()
p['executionStats']
返回了987个文档
{'executionSuccess': True,'nReturned': 987,'executionTimeMillis': 20,'filter': {'geometry': {'$eq': {'type': 'Point',44.23262]}}},'executionTimeMillisEstimate': 1,'advanced': 987,'needTime': 38624,'allPlansExecution': []}
有人可以帮我解释一下为什么我的“ $ near”命令什么都没找到吗?我的代码错了吗?谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。