我正在抓取网站并形成文件 将这些文件插入mongodb我收到重复密钥错误
E11000重复密钥错误集合:reviews.newreviews index: id dup key:{:ObjectId('5b1a0a6070c52911c8848c71')}
我正在使用pymongo,插入第一个文件并在插入第二个文件时引发错误 据我所知_id是由mongodb生成的独一无二的 祝你有任何帮助
review = [{'contentSnippet': "Purchased Fridge from and Spirit Delivery would not follow up with phone calls and when Spirit Delivery contacted me exactly 47 days later after the delivery, they were extremely rude and offensive...", 'createdDateTime': '2018-04-25T00:00:00', 'title': '', 'listingId': '', 'reviewerName': 'Clas', 'rating': '1', 'reviewerUrl': 'xxxx', 'sourceId': 20003, 'sourceName': 'websitename', 'domain': 'com', 'srid': '', 'url': 'https://xxx', 'modifiedDateTime': '2018-04-25T00:00:00', 'publishedDateTime': '2018-06-08T10:17:26', 'merchantId': 891, 'isoId': 358, 'reviewId': '9ae5e749b296484548066617d0e18109735e45ef'},{}]
def uploaddata(self,col_name,review):
try:
self.checkmongoconnection()
db = self.conn.reviews
col=db[col_name]
print(review)
for objs in review:
col.insert(objs)