MongoTimeoutException:等待连接10000毫秒后超时

时间:2018-06-28 04:06:36

标签: mongodb pyspark apache-spark-sql

我正在尝试将mongodb与pyspark连接。当我试图像这样将数据从mongodb加载到pyspark时,它抛出了此异常。有人可以帮我吗?

    >>>df = spark.read.format('com.stratio.datasource.mongodb')\
    .options(host='localhost:7077',database='my_db', \ collection='my_coll').load()

....

Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/phamgiabao/spark-2.3.1-bin-hadoop2.7/python/pyspark/sql/readwriter.py", line 172, in load
        return self._df(self._jreader.load())
      File "/home/phamgiabao/spark-2.3.1-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
      File "/home/phamgiabao/spark-2.3.1-bin-hadoop2.7/python/pyspark/sql/utils.py", line 63, in deco
        return f(*a, **kw)
      File "/home/phamgiabao/spark-2.3.1-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py", line 328, in get_return_value
    py4j.protocol.Py4JJavaError: An error occurred while calling o140.load.
    : com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:7077, type=Unknown, state=Connecting}]
        at com.mongodb.BaseCluster.getDescription(BaseCluster.java:128)
        at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:394)
        at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:571)
        at com.mongodb.DBTCPConnector.getReplicaSetStatus(DBTCPConnector.java:362)
        at com.mongodb.Mongo.getReplicaSetStatus(Mongo.java:446)
        at com.mongodb.DB.getCommandReadPreference(DB.java:82)
        at com.mongodb.DB.command(DB.java:317)
        at com.mongodb.DB.command(DB.java:299)
        at com.mongodb.DBCollection.getStats(DBCollection.java:1808)
        ....

0 个答案:

没有答案