如何在php中获取MongoDB更新/删除操作的状态?

I am using this

function delete($col,$condition = array()){
    $bulk = new MongoDB\Driver\BulkWrite;
    $bulk->delete($condition, ['limit' => 1]);

    $manager = new MongoDB\Driver\Manager($this->mongo);
    $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
    $result = $manager->executeBulkWrite($this->db.'.'.$col, $bulk, $writeConcern);
    var_dump($result);

}

And the code works and getting output like bellow

object(MongoDB\Driver\WriteResult)#30 (9) { ["nInserted"]=> int(0) ["nMatched"]=> int(0) ["nModified"]=> int(0) ["nRemoved"]=> int(0) ["nUpserted"]=> int(0) ["upsertedIds"]=> array(0) { } ["writeErrors"]=> array(0) { } ["writeConcernError"]=> NULL ["writeConcern"]=> array(4) { ["w"]=> string(8) "majority" ["wmajority"]=> bool(true) ["wtimeout"]=> int(1000) ["journal"]=> NULL } }

Now I can't convert the object to array. How to get the properties like "nRemoved" / "nUpdated" from the object?

You can do it like this:

$bulk = new MongoDB\Driver\BulkWrite(['ordered' => false]);
$bulk->update(
    $condition,
    $data,
    $n_opts
);
if($result = $this->mongo->executeBulkWrite($this->db.'.'.$collection, $bulk)){
    if(($result->getMatchedCount() > 0 AND $result->getModifiedCount() > 0) OR ($result->getMatchedCount() == 0 AND $result->getUpsertedCount() > 0)){
        return true;
    }else{
        return false;
    }
}else{
    return false;
}

To return deletes count:

$result->getDeletedCount();

More info about this methods here: http://php.net/manual/en/class.mongodb-driver-writeresult.php