Created
January 20, 2017 12:40
-
-
Save thejeshgn/ea0074077b6fcd6c0108b2a4380fc354 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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