Php 类别';MongoDB\Cient';找不到
我正在使用以下代码创建到MongoDB服务器的连接,以便创建数据库和其他内容,但我一直没有找到Php 类别';MongoDB\Cient';找不到,php,mongodb,Php,Mongodb,我正在使用以下代码创建到MongoDB服务器的连接,以便创建数据库和其他内容,但我一直没有找到类“MongoDB\Cient”。我真的需要帮助 <?php $client = new MongoDB\Client('mongodb://localhost:27017'); $db = $client->reach; $collection = $db->messages; $collection->insertOne($record);
类“MongoDB\Cient”
。我真的需要帮助
<?php
$client = new MongoDB\Client('mongodb://localhost:27017');
$db = $client->reach;
$collection = $db->messages;
$collection->insertOne($record);
?>
其中,$record
是一些记录
另外,
$mng=new MongoDB\Driver\Manager(“mongodb://localhost:27017");代码>连接,我可以使用它与任何已创建的数据库通信(使用命令行)。所以,我想问一下MongoDB\Driver\Manager
能否替代MongoDB\Client
?经过所有的努力,这解决了问题
使用composer安装:
$ composer require "mongodb/mongodb=^1.0.0"
OUTPUT:
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Installing mongodb/mongodb (1.0.0)
Downloading: 100%
Writing lock file
Generating autoload files
用法:
<?php
require 'vendor/autoload.php'; // include Composer goodies
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->demo->beers;
$result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );
echo "Inserted with Object ID '{$result->getInsertedId()}'";
?>