0
我正在使用PySpark进行一些大规模处理并将一些结果保存到MongoDB实例。我正在使用mongo-spark-connector_2.11-2.0.0.jar
将数据框写入MongoDB。如何处理PySpark中的MongoDB异常?
df.write.format("com.mongodb.spark.sql.DefaultSource").option("spark.mongodb.output.uri", "mongodb://username:[email protected]:10203/mydb.mycollection").mode("overwrite").save()
有时候我例外,例如ConnectionException
,MongoCommandException
等。所以我想处理这些例外。所以我添加了这些异常处理代码片段,但是我得到了ImportError: No module named com.mongodb
。
try:
df.write.format("com.mongodb.spark.sql.DefaultSource").option("spark.mongodb.output.uri", "mongodb://username:[email protected]:10203/mydb.mycollection").mode("overwrite").save()
except MongoCommandException:
err_code = MongoCommandException.getErrorCode()
if err_code == int(16):
print "Request size is too large to write to Mongo"
所以能有人对你帮助我如何使用mongo-spark-connector_2.11-2.0.0.jar
有趣。谢谢! –