在PHP中“类‘的MongoDB \驱动程序\经理’找不到”

问题描述 投票:0回答:1

我安装的MongoDB库作曲:

composer require jenssegers/mongodb

我得到的错误:“类‘的MongoDB \驱动程序\经理’找不到”,

我尝试了很多事情,但问题并没有解决,但最后我发现,类文件真的没有图书馆现有的!我还没有发现它无论如何...

我在想什么?

我在哪里可以找到全包的MongoDB在PHP?

请注意的是:类似的问题不提缺少类文件。

php mongodb composer-php
1个回答
1
投票

通常你的代码应该包含一个链接,类似于以下正确的路径是“供应商/ autoload.php”:

  $DB_CONNECTION_STRING="mongodb://YourCredentials";
  require '../../vendor/autoload.php';

然后,如果你使用的MongoDB \驱动程序\经理,MongoDB的驱动的现代版,你有什么事情,如在你的代码,这些CRUD操作:

创建集合在一个文档:

$bulkWrite = new MongoDB\Driver\BulkWrite;
$doc=['name' => 'John', age => 33, profession => 'Guess what?'];
$bulk->insert($doc);
$mongoConn->executeBulkWrite('db.col', $bulkWrite);

按名称与极限读取集合中的文件:

$filter = ['name' => 'John'];
$options = ['limit' => 2];
$query = new MongoDB\Driver\Query($filter, $options);
$mongoConn->executeQuery('db.MyCollection', $query);

通过MongoDB的_id与极限读取集合中的文件:

$filter = ['_id' => new MongoDB\BSON\ObjectID( '5bdf54e6d722dc000f0aa6c2' )];
$options = ['limit' => 2];
$query = new MongoDB\Driver\Query($filter, $options);
$mongoConn->executeQuery('db.MyCollection', $query);    

更新集合中的文件:

$bulkWrite = new MongoDB\Driver\BulkWrite;
$filter = [];
$update = ['$set' => array()];
$options = ['multi' => false, 'upsert' => false];
$bulkWrite->update($filter, $update, $options);
$mongoConn->executeBulkWrite('db.MyCollection', $bulkWrite);    

集合中删除文件 - 删除:

$bulkWrite = new MongoDB\Driver\BulkWrite;
$filter = ['name' => 'John', age => 33];
$options = ['limit' => 1];
$bulkWrite->delete($filter, $options);
$mongoConn->executeBulkWrite('db.col', $bulkWrite);
© www.soinside.com 2019 - 2024. All rights reserved.