我用api得到了json的某种数据格式。我用我的代码为它们打开了一个文件。我想将我的文件上传到mongodb上,但是我不能。
最新版本的mongodb以及最新版本的python。
conn=pymongo.MongoClient('localhost',27017)
database=conn['mydb']
collection=database['mycol']
........( ı pull of somedata with API)
with open('dataPost.json','w',encoding="iso-8859-1") as outfile:
t=json.dump(results,outfile)
collection.insert_one(t)
TypeError:文档必须是dict,bson.son.SON,bson.raw_bson.RawBSONDocument的实例,或者是从collections.MutableMapping继承的类型
我可以创建文件。但是文件无法上传mongodb