我有几百个JSON文件要插入到mongo数据库中。我写了这段代码,但它没有用。我收到错误
TypeError: 'str' object does not support item assignment
代码如下:
import glob
from pymongo import MongoClient
client = MongoClient('localhost',27017)
path = '/home/rahul/Desktop/*.json'
files = glob.glob(path)
db = client.helloworld
c = db.docs
for f in files:
c.insert(f)