yii\mongodb\file\Collection::remove PHP Method

remove() public method

public remove ( $condition = [], $options = [] )
    public function remove($condition = [], $options = [])
    {
        $fileCollection = $this->getFileCollection();
        $chunkCollection = $this->getChunkCollection();
        if (empty($condition) && empty($options['limit'])) {
            // truncate :
            $deleteCount = $fileCollection->remove([], $options);
            $chunkCollection->remove([], $options);
            return $deleteCount;
        }
        $batchSize = 200;
        $options['batchSize'] = $batchSize;
        $cursor = $fileCollection->find($condition, ['_id'], $options);
        $deleteCount = 0;
        $deleteCallback = function ($ids) use($fileCollection, $chunkCollection, $options) {
            $chunkCollection->remove(['files_id' => ['$in' => $ids]], $options);
            return $fileCollection->remove(['_id' => ['$in' => $ids]], $options);
        };
        $ids = [];
        $idsCount = 0;
        foreach ($cursor as $row) {
            $ids[] = $row['_id'];
            $idsCount++;
            if ($idsCount >= $batchSize) {
                $deleteCount += $deleteCallback($ids);
                $ids = [];
                $idsCount = 0;
            }
        }
        if (!empty($ids)) {
            $deleteCount += $deleteCallback($ids);
        }
        return $deleteCount;
    }