如何使用PHP在mongodb中使用_id更新多个文档?

时间:2017-04-19 05:18:14

标签: php mongodb php-mongodb

我使用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);
?>

0 个答案:

没有答案