我使用Mongodb和PHP
MongoConnection
class mongoManager{
private $db;
private $collection;
private function mongoConnect($collName){
$con = new Mongo(URI);
//$this->databaseName = $dbname;
$this->db = $con->dbname;
$this->collection = $this->db->$collName;
return $con;
}
public function mongoUpdate($collName, $idFind, $updateValues){
if($this->mongoConnect($collName)){
if($this->collection->update($idFind, $updateValues)){
return 1;
}
else{
return 0;
}
}
}
}
我有包含ID的php数组,我想用以下数组ID更新文档。
Array
(
[0] => 58ec62e5ae8715a410000003
[1] => 58ec6227ae8715a410000002
)
我已经使用php跟踪脚本更新了单个文档,但我很难与多个文档更新
singleDocUpdate.php
<?php
$mongoObj = new mongoManager();
$et_id = array('_id'=>new MongoId($_GET['id']));
$updateValues = array(
"\$set"=> array(
"stat" => "A",
"approved_by" => $_SESSION['id'],
"approved_date" => $today
)
) ;
$res = $mongoObj->mongoUpdate('AllEvents', $evnt_id, $updateValues);
?>