Discrepancy while inserting data in MongoDB through pymongo -
i have json file 20 records. tried inserting data json mongodb through python(pymongo specific). following python code.
from pymongo import mongoclient pprint import pprint import json # creating mongo db client , connecting # fantasyscout database. # inserting players in collection(table) # players. client = mongoclient() db = client.fantasyscout # reading data dumper json file open("c:\\team.level.json") db_data: data = json.load(db_data) # reading every element in json data , # inserting in db. print len(data) print data[str(20)] element in range(1,++len(data)): db.team_level.insert(data[str(element)])
the len(data) holds value 20 (confirmed printing in python). though after running script, no. of records inserted 19 , data["20"]
not inserted. after changing range manually (1,21), script enters 20 records. missing trivial . please point out mistake.
for loop 0 2, therefore running 3 times.
for x in range(0, 3): print "we're on time %d" % (x)
that means need iterate 0
not 1
Comments
Post a Comment