首页 > 解决方案 > PHP中的MongoDB更新:在多个ID上更新一个变量(表示为变量)

问题描述

我需要根据 PHP 最后一页中选定的复选框将文本标签更新到 MongoDB 数据库中。

例如,

我选择了 5 个复选框并在文本框中输入了一个文本标签。在下一页中,我需要编写更新语句以将文本标签更新到 5 个选中复选框的数据库中。这意味着 5 个选中的复选框的路径应该具有更新到数据库中的相同文本标签。数据库不包含文本标签属性。notes: selectedIds = selected checkboxes'paths; clusters 没有 textLabel,所以我必须在这里创建?

$manager = new MongoDB\Driver\Manager('mongodb://username:password@localhost:xxxx/db_name?authSource=db_name'); (the $manger works, it includes the information of username, passwork, db_name, and local_host). 
$updateResult = array();
  foreach($selectedImages as $selectedImages){
$result = $manager->update(
  array("filename.anonPath" => $selectedImages),
  array("clusters_r37_mcs100.textLabel" => $textLabel),
  array_push($updateResult,$result);
);
}
print_r("$updateResult");

我有一个问题:

无论我是否成功更新,终端都不会显示任何内容。但是,当我签入 MongoDB 数据库时,我没有看到任何 textLabel 更新。

谢谢你。

标签: phparraysmongodbmongodb-querysql-update

解决方案


推荐阅读