php - 尝试使用 PHP 在 MongoDB 中执行查询
问题描述
我只是想配置 PHP 访问我的 MongoDB 数据库。首先,MongoDB 驱动程序安装在 PHP 中,并更新了 php.ini。下面的代码没有任何警告或错误,显然一切都很好:
$options = [
'username' => 'user',
'password' => '123456',
'authSource' => 'database',
];
$mongo = new MongoDB\Driver\Manager('mongodb://localhost:27017', $options);
$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
$document = array("key" => "value", "another_key" => "another_value"); //...and so on...
$bulk->insert($document);
$result = $mongo->executeBulkWrite('db.mycollection', $bulk, $writeConcern);
但是,当我检查我的数据库时,什么也没发生:没有插入任何文档!!!我做错了什么???
解决方案
推荐阅读
- c# - 根据已传递的 Class 自动生成 UI
- javascript - 使用 JavaScript 写入 Firebase 存储会导致“跨源请求被阻止”
- python-3.x - VS Code Python 3-悬停在变量类型上
- node.js - Momentjs 在当前位置获取时间
- regex - 正则表达式删除 -i- 之后的所有内容(使用 -i-)
- python - QPushButton.clicked() 在使用 .ui 表单自动装配时触发两次
- java - 如何为 JTextfield 中的数值设置范围(例如 1 - 20)
- for-loop - for 循环是对引用还是按值操作?
- python - 如何强制 VSCode 使用 Python 3 而不是 Python 2?
- python - 将图例移出图形时,由线条和图片组成的matplotlib图例标签丢失线条