我试图将json文件导入MangoDB,但出现错误:
File "<ipython-input-2-64b0e1ec4bba>", line 13
data = json.load(f)
^
IndentationError: expected an indented block
我的代码是:
import json, pymongo
from pymongo import MongoClient
cluster = MongoClient('mongodb+srv://Rokaya:140296@cluster0.mc9wz.mongodb.net/Hotel_Test?retryWrites=true&w=majority')
db = cluster['Hotel_Test']
collection = db['Hotel_Reviews_Test']
with open('/Users/rokayadarai/Desktop/Coding/DataSets/Hotel_Reviews.json') as f:
data = json.load(f)
collection.insert_many(data)
cluster.close()
我做错了什么?我没看见什么吗
您需要如上所述缩进代码,因为您使用的“with”python需要缩进,以便它知道如何处理您打开的.json文件
相关问题 更多 >
编程相关推荐