首页 > 解决方案 > MongoDB Atlas:MongoCursorTimeoutException(错误)::读取0字节后读取超时,等待-1.000000秒

问题描述

我正在尝试将我的 mongo 集群转移到 mongodb-atlas。当我尝试连接到 mongoDB 时,它正在建立连接(我可以从 atlas 日志和 php-mongodb 驱动程序中看到),但它会立即抛出错误。

我在 php-driver 日志中发现了以下内容

2018-04-27 02:27:02 :: IO (FINE): getting reply
2018-04-27 02:27:02 :: IO (FINE): getting cursor header
2018-04-27 02:27:02 :: CON (FINE): Setting the stream timeout to -1.000000
2018-04-27 02:27:02 :: MongoCursorTimeoutException (ERROR): <atlashost:port>: Read timed out after reading 0 bytes, waited for -1.000000 seconds`

当它连接到我自己的集群时,相同的代码运行良好。

版本和其他一切都是一样的。版本:3.6

我被困在调试中,但找不到任何东西。

任何帮助,将不胜感激。

下面是显示连接流程的代码:

final class mongoConnection {
    static function createConnection() {
        $ctx = stream_context_create(array(
            "ssl" => array(
                "verify_peer" => false
            ))
        );
        self::$connection = new MongoClient("mongodb://user:password@host:port/admin&ssl=true",array("replicaSet" => 'replicaNamw'),array("context" => $ctx));
        return self::$connection;
    }
}

function connectMongoDb()
{
    $mongo = mongoConnection::createConnection();
    $m = $mongo->getConnection();
    $db = $m->selectDB('DATABASE');
    return $db;
}

$mongoDb = $this->connectMongoDb();
$collection->find()->sort(array('_id' => -1))->limit(100); //this is one of the line where I am getting error in my application 

的输出var_dump(self::$connection)

object(MongoClient)[21]
  public 'connected' => boolean true
  public 'status' => null
  protected 'server' => null
  protected 'persistent' => null

错误 :

 ( ! ) MongoCursorTimeoutException: <host>:<port>: Read timed out after reading 0 bytes, waited for -1.000000 seconds in <filename> on line 33

标签: phpmongodb

解决方案


推荐阅读