使用x509连接php mongodb

使用x509连接php mongodb,php,mongodb,x509certificate,Php,Mongodb,X509certificate,我已经安装了传统的mongo php 1.6.10驱动程序和支持的1.2.5 mongodb php驱动程序。php版本是Debian8上的5.6.29 传统驱动程序和受支持的驱动程序都可以使用基本凭据进行连接 只有旧版驱动程序可以使用x509证书进行连接 当尝试对集合执行简单findOne时,受支持的驱动程序会导致以下异常 PHP Fatal error: Uncaught exception 'MongoDB\Driver\Exception\RuntimeException' with

我已经安装了传统的mongo php 1.6.10驱动程序和支持的1.2.5 mongodb php驱动程序。php版本是Debian8上的5.6.29

传统驱动程序和受支持的驱动程序都可以使用基本凭据进行连接

只有旧版驱动程序可以使用x509证书进行连接

当尝试对集合执行简单findOne时,受支持的驱动程序会导致以下异常

PHP Fatal error:  Uncaught exception 'MongoDB\Driver\Exception\RuntimeException' with message 'SCRAM Failure: invalid salt length of 0 in sasl step2'
我正在为Mongodb驱动程序使用Mongodb客户端库

下面是我正在使用的解释代码

<?php
$server = 'mongodb://uat-a:27017,uat-b:27017,uat-c:27017';
$options = [
    'replicaSet' => 'rs-uat',
    'username' => 'CN=my-user,OU=user,O=NA,L=Place,ST=State,C=GB',
    'authMechanism' => 'MONGODB-X509',
    'authSource' => '$external',
    'ssl' => true,
    'connect' => true,
];
$driverOptions = [
    'context' => stream_context_create(
        [
            'ssl' => [
                'local_cert' => '/etc/local-cert.pem',
                'cafile' => '/etc/cafile.pem',
            ],
        ]
    ),
];
$database = 'uatdata';

$client = new MongoDB\Client($server, $options, $driverOptions);
$db = $client->selectDatabase($database);

$doc = $db->selectCollection('errors')->findOne([], ['projection' => ['timestamp' => 1, 'uri' => 1]]);

答案是在URI字符串中传递
authMechanism
选项。e、 g

mongodb://uat-a:27017,uat-b:27017,uat-c:27017/?authMechanism=MONGODB-X509

更详细的解释可以在这里找到