我想将一个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
我如何解决这个问题?提前谢谢
insert_many为每个documentation获取一个文档数组
提供一个数组或使用insert\u-one来获取单个文档
相关问题 更多 >
编程相关推荐