Cml\Db\MongoDB\MongoDB::delete PHP Метод

delete() публичный Метод

根据key值删除数据
public delete ( string $key = '', boolean $and = true, mixed $tablePrefix = null ) : boolean
$key string eg: 'user-uid-$uid'
$and boolean 多个条件之间是否为and true为and false为or
$tablePrefix mixed 表前缀 不传则获取配置中配置的前缀
Результат boolean
    public function delete($key = '', $and = true, $tablePrefix = null)
    {
        is_null($tablePrefix) && ($tablePrefix = $this->tablePrefix);
        $tableName = $condition = '';
        empty($key) || (list($tableName, $condition) = $this->parseKey($key, $and, true, true));
        $tableName = empty($tableName) ? $this->getRealTableName(key($this->table)) : $tablePrefix . $tableName;
        if (empty($tableName)) {
            throw new \InvalidArgumentException(Lang::get('_PARSE_SQL_ERROR_NO_TABLE_', 'delete'));
        }
        $condition += $this->sql['where'];
        if (empty($condition)) {
            throw new \InvalidArgumentException(Lang::get('_PARSE_SQL_ERROR_NO_CONDITION_', 'delete'));
        }
        $bulk = new BulkWrite();
        $bulk->delete($condition);
        $result = $this->runMongoBulkWrite($tableName, $bulk);
        Cml::$debug && $this->debugLogSql('BulkWrite DELETE', $tableName, $condition);
        return $result->getDeletedCount();
    }