PHP的MongoDB的,致命错误:类“的MongoDB \驱动程序\管理器”中找不到

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

image for mongo info

MongoDB的外壳版本V3.4.1

MongoDB的驱动v1.6.14

XAMPP V3.2.1,阿帕奇/ 2.4.16(Win32的)的OpenSSL / 1.0.1p PHP / 5.6.12

I M运行首次获得此问题plz帮助我。

致命错误:类 '的MongoDB \驱动\管理器' H中未找到:\ XAMPP \ htdocs中\ WWW \ phpmongodb \厂商\ mongodb的\ mongodb的\ SRC \上线81 Client.php

php mongodb
1个回答
0
投票

我有同样的错误之前,我设置了MongoDB的添加了以下链接“供应商/ autoload.php”。在很多情况下,你需要检查你的主机。它开始工作,我的代码看起来像以下后:

  $DB_CONNECTION_STRING="mongodb://YourCredentials";
  require '../../vendor/autoload.php';
  $manager = new MongoDB\Driver\Manager( $DB_CONNECTION_STRING );

然后,如果你使用的MongoDB \驱动程序\经理,MongoDB的驱动的现代版,你有什么事情看起来像这样:

创建集合在一个文档:

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

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

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

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

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

集合中更新文件:(了解更多关于选择UPSERT和多here

$bulkWrite = new MongoDB\Driver\BulkWrite;
$filter = ['name' => 'John'];
$update = ['$set' => ['name' => 'Smith', age: 35, profession => 'Guess what?']];
$options = ['multi' => false, 'upsert' => false];
$bulkWrite->update($filter, $update, $options);
$manager->executeBulkWrite('db.MyCollection', $bulkWrite);    

集合中删除文件 - 删除:

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