0
當我試圖向MongoDB中插入一大塊GeoJSON時,我收到此消息:TypeError - document must be an instance of dict, bson.son.SON, or other type that inherits from collections.MutableMapping
。PyMongo TypeError - 文檔必須是dict,bson.son.SON或從集合繼承的其他類型的實例。可變映射
該塊是這樣的:
new_points = ['{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}', '{"coordinates": [-179.75, 89.75], "simulation": "aet_whe", "type": "Point"}']
而插入電話是這樣的:
result = points.insert_many(new_points)
這本詞典與GeoJSON的文庫中產生的,採用這種結構:
class GenerateDocument:
def __init__(self, x, y, simulation_variable):
self.x = x
self.y = y
self.sim = simulation_variable
@property
def __geo_interface__(self):
return {'type': 'Point', 'coordinates': (self.x, self.y), 'simulation': self.sim}
任何暗示解決這個問題?我是否生成錯誤類型的geojson?
看起來像一串字符串給我。也許你應該首先'[json.loads(coords)coords in new_points]'並且傳遞它呢? –
@ Two-BitAlchemist它的工作!謝謝 :) –