php - 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
解决方案
推荐阅读
- c# - 如何在 SQL Server Express 中创建表 - Microsoft
- microsoft-teams - 如何在传入的 webhook 消息中发送超链接?
- node.js - 从 postgis 到图像的栅格
- javascript - 追加元素后如何添加事件函数?
- react-native - 从 google api 获取无法正常工作?
- python - python 3中的单行“编织”连接
- angular - Angular Parse 错误:在预期表达式的位置得到插值 ({{}})
- html - 对齐两个 div 以使第二个 div 获得所需的所有空间
- networking - 为什么设置静态ip时需要DNS服务器
- ruby - RSpec:断言模拟是正确的