python 读取Json文件并插入Mongodb #mongo #python

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 读取Json文件并插入Mongodb #mongo #python相关的知识,希望对你有一定的参考价值。

with open('agile_users_geo.json') as data_file:
    data = json.load(data_file)
    for item in data['data']:
        key = {"id": item['features']['id']}
        data = {"geo_type": item['features']['geo_type'],
                "location": item['features']['location'],
                "name": item['features']['name'],
                "primary_geo": item['features']['primary_geo'],
                "screen_name": item['features']['screen_name'],
                "tweets": item['features']['tweets']}
        collection.update(key, data, upsert=True)

以上是关于python 读取Json文件并插入Mongodb #mongo #python的主要内容,如果未能解决你的问题,请参考以下文章