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();
}