Py学习  »  MongoDB

PHP mongoDB集群连接字符串不工作

hrishi • 4 年前 • 515 次点击  

$client = new MongoClient('mongodb+srv://username:password@urlToCluster');

它给我的错误是

Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known' 

无法使用连接字符串连接

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54376
 
515 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Alex Blex
Reply   •   1 楼
Alex Blex    5 年前

MongoClient 很久以前就被弃用了,并且可能不支持新的副本集语法。

https://docs.atlas.mongodb.com/driver-connection/ 建议使用最新版本 Mongodb driver

$client = new MongoDB\Client('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');