如何从PHP连接我的MongoDB Atlas帐户?

nwsw7zdq  于 2023-05-27  发布在  PHP
关注(0)|答案(1)|浏览(96)

我无法连接到我的MongoDB Atlas帐户。
有什么办法吗?

<?php

    $server = "mongodb+srv://admin:<mypassword>@m001-basics-ivutt.mongodb.net/video?retryWrites=true";

    // Connecting to server
    $c = new MongoDB\Client( $server );

    if($c->connected)
        echo "Connected successfully";
    else
        echo "Connection failed";

?>

脚本不返回任何内容。

mzsu5hc0

mzsu5hc01#

试试这个

$client = new MongoDB\Client(
    'mongodb+srv://kay:myRealPassword@cluster0.mongodb.net/?ssl=true&authSource=admin&serverSelectionTryOnce=false&serverSelectionTimeoutMS=15000"');

$db = $client->test;

有关更多详情,请访问
https://docs.atlas.mongodb.com/driver-connection/

相关问题