x = mycol.insert_one({
"name":List_Name.keys(),
"time": List_Name.values()**strong text**``
})
tried this doesnt work`x = mycol.insert_one({
"name":List_Name.keys(),
"time": List_Name.values()
})
List_Name
是一本字典。mongo新手上面写着-
bson.errors.InvalidDocument:无法对类型为<类"dict_keys">
keys()
方法返回一个<class 'dict_keys'>
对象,您需要将其强制转换为如下字符串:
separator = ", "
list_of_names = separator.join(List_Names.keys()) # keys separated by comma and space
x = mycol.insert_one({
"name":list_of_names,
})