2
我的集合中的文件看起來是這樣的 -
{'_id' : 'Delhi1', 'loc' : [28.34242,77.656565] }
{'_id' : 'Delhi2', 'loc' : [27.34242,78.626523] }
{'_id' : 'Delhi3', 'loc' : [25.34242,77.612345] }
{'_id' : 'Delhi4', 'loc' : [28.34242,77.676565] }
我想用pymongo,找出基於輸入經緯度有關文件申請聚集。我創建了'loc'的索引。這是我迄今爲止所做的 -
pipeline = [{'$geoNear':{'near': [27.8787, 78.2342],
'distanceField': "distance",
'maxDistance' : 2000 }}]
db['mycollection'].aggregate(pipeline)
但這不適合我嗎?如何正確使用這個?
沒有,在pymongo,我們需要包裝集合名稱和操作員用戶名在括號內包裝,2 - 在Python邏輯運算符Propercase – userxxx
最值得注意的是這裏的'近:{座標:27.8787,78.2342]} '無效。 ''near''選項可以直接使用座標數組或「GeoJSON對象」{「類型」:「點」,「座標」:[27.8787,78.2342]}。無論如何,@userxxx都回答了自己的問題,增加了「spherical」:True',它在Python中是「布爾值」的正確形式,可以是「True」或「False」。在閱讀問題時注意標籤(不要忘記在問題標題和正文中同時使用pymongo)。 Python與JSON和JavasScript具有「相似」的語法,但有所不同。 –