使用 mongodb 驱动程序 1.5.2 从共享主机连接到 mongodb atlas 免费层并尝试编写简单文档会出现以下错误。我究竟做错了什么?
$manager = new MongoDB\Driver\Manager("mongodb://admin:admin@test-shard-00-00-rbgc.mongodb.net:27017/db?ssl=false&replicaSet=test-shard-0&authSource=admin&serverSelectionTryOnce=false");
var_dump($manager);
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['x' => 1]);
$manager->executeBulkWrite('db.collection', $bulk);
致命错误:未捕获的 MongoDB\Driver\Exception\ConnectionTimeoutException:未找到合适的服务器:serverselectiontimeoutms 超时:/Applications/AMPPS 中的 [connection closed calling ismaster on 'test-shard-00-00-waf4c.mongodb.net:27017'] /www/mongodb/liveserver.php:63
当我对 $manager 进行 var_dump 时,我得到:
对象(MongoDB\Driver\Manager)#1 (2) { ["uri"]=> string(64) "admin:admin@test-shard-00-00-rbgc.mongodb.net:27017/" ["cluster "]=> 数组(0) { } }
我也尝试了以下方法,但错误始终相同:
$manager = new MongoDB\Driver\Manager('mongodb://admin:admin@pirat-shard-00-00-vegbq.gcp.mongodb.net:27017/db?ssl=falseweak_cert_validation=false');
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['x' => 1]);
$bulk->insert(['x' => 2]);
$bulk->insert(['x' => 3]);
$manager->executeBulkWrite('db.collection2', $bulk);