Closed
Description
Description
The message is:
Fatal error: Uncaught exception 'MongoDB\Driver\Exception\ConnectionTimeoutException' with message 'No suitable servers found (`serverSelectionTryOnce` set): [connection timeout calling ismaster on 'cluster0-shard-00-00-b2gpc.mongodb.net:27017'] [connection timeout calling ismaster on 'cluster0-shard-00-01-b2gpc.mongodb.net:27017'] [TLS handshake failed: -9806 calling ismaster on 'cluster0-shard-00-02-b2gpc.mongodb.net:27017']' in /Users/jia/Sites/vendor/mongodb/mongodb/src/Collection.php:515
Stack trace:
#0 /Users/jia/Sites/vendor/mongodb/mongodb/src/Collection.php(515): MongoDB\Driver\Manager->selectServer(Object(MongoDB\Driver\ReadPreference))
#1 /Users/jia/Sites/testPem.php(25): MongoDB\Collection->find()
#2 {main} thrown in /Users/jia/Sites/vendor/mongodb/mongodb/src/Collection.php on line 515
It's not happening all the time, but I couldn't figure out what cause it. The code is
<?php
require 'vendor/autoload.php';
$server = "mongodb://csci571:<password>@cluster0-shard-00-00-b2gpc.mongodb.net:27017,cluster0-shard-00-01-b2gpc.mongodb.net:27017,cluster0-shard-00-02-b2gpc.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin";
$ctx = stream_context_create(array(
"ssl" => array(
"cafile" => "/usr/local/etc/openssl/cert.pem",
"allow_self_signed" => false,
"verify_peer" => true,
"verify_peer_name" => true,
"verify_expiry" => true,
),
)
);
$client = new MongoDB\Client(
$server,
array("ssl" => true),
array("context" => $ctx));
$database = $client->test;
$collection = $database->student;
$cursor = $collection->find(['mail' => '']);
function console_log( $data ){
echo '<script>';
echo 'console.log('. json_encode( $data ) .')';
echo '</script>';
}
?>
First time to use mongodb, I cannot find where the log is.