问题描述
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 (将#修改为@)