Skip to content

Instantly share code, notes, and snippets.

@thejeshgn
Created January 20, 2017 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejeshgn/ea0074077b6fcd6c0108b2a4380fc354 to your computer and use it in GitHub Desktop.
Save thejeshgn/ea0074077b6fcd6c0108b2a4380fc354 to your computer and use it in GitHub Desktop.
import json
import pymongo
from pymongo import Connection
DATABASE_HOST = "mongodb://localhost:27017"
connection = Connection(DATABASE_HOST)
db = connection['country']
#drop first
db.states.remove()
db.districts.remove()
db.taluks.remove()
db.villages.remove()
states = json.loads(open('/home/thej/Downloads/rdata.js').read())
for state in states:
districts = state['districts']
del state['districts']
print state['stname']
db.states.insert(state)
for district in districts:
taluks = district['taluks']
del district['taluks']
print district['distName']
db.districts.insert(district)
for taluk in taluks:
villages = taluk['villages']
del taluk['villages']
db.taluks.insert(taluk)
for village in villages:
db.villages.insert(village)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment