mongodb-php-aunthentication不起作用



我尝试了它加载的所有方法很长时间,请帮助我解决这个问题

<?php
//Include Composer's autoloader
require_once __DIR__ . "/commons/mongo/mongodb/autoload.php";
//Create a MongoDB client and open connection to Amazon DocumentDB
$client = new MongoDBClient("mongodb://username:password@13.212.232.159:27017,54.169.109.109:27017,54.255.203.67:27017");
//Specify the database and collection to be used
$col = $client->sampledatabase->samplecollection;
//Insert a single document
$result = $col->insertOne( [ 'hello' => 'Amazon DocumentDB'] );
//Find the document that was previously written
$result = $col->findOne(array('hello' => 'Amazon DocumentDB'));
//Print the result to the screen
print_r($result);
?>

您的连接方式似乎有点不对劲。

  • 我看到的是IP,而不是亚马逊文档数据库端点
  • 我看不到TLS文件

根据官方文件,这应该是连接的方式:

<?php
//Include Composer's autoloader
require 'vendor/autoload.php';
$TLS_DIR = "/home/ubuntu/rds-combined-ca-bundle.pem";
//Create a MongoDB client and open connection to Amazon DocumentDB
$client = new MongoDBClient("mongodb://<sample-user>:<password>@sample-cluster.node.us-east-1.docdb.amazonaws.com:27017/?retryWrites=false", ["tls" => "true", "tlsCAFile" => $TLS_DIR ]);
//Specify the database and collection to be used
$col = $client->sampledatabase->samplecollection;
//Insert a single document
$result = $col->insertOne( [ 'hello' => 'Amazon DocumentDB'] );
//Find the document that was previously written
$result = $col->findOne(array('hello' => 'Amazon DocumentDB'));
//Print the result to the screen
print_r($result);
?>

sample-cluster.node.us-east-1.docdb.amazonaws.com需要由端点更改的位置

最新更新