【发布时间】:2020-04-22 22:58:43
【问题描述】:
我想将结构如下的 JSON 文件导入 MongoDB:
{
"a": 1,
"aa": 1,
"aaa": 1,
"aah": 1,
"aahed": 1,
"aahing": 1,
"aahs": 1,
"aal": 1,
"aalii": 1
}
但是当我运行以下代码时:
def import_dictionary(collection):
with open(dictionary, 'r', encoding='utf-8') as f:
file_data = json.load(f)
document = RawBSONDocument(BSON.encode(file_data))
collection.insert_many(document)
我收到以下错误:
TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping
我该如何解决这个问题?提前致谢!
【问题讨论】: