Skip to content

Instantly share code, notes, and snippets.

@ninodafonte
Last active October 30, 2017 06:42
Show Gist options
  • Save ninodafonte/1ca631fd8f916cb1f61ee702b5bb4633 to your computer and use it in GitHub Desktop.
Save ninodafonte/1ca631fd8f916cb1f61ee702b5bb4633 to your computer and use it in GitHub Desktop.
Read Json file and insert into 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment