protected function afterDelete() { try { if ($this->storage == 'gridfs') { $collChunkName = $this->collectionNameGridFS() . ".chunks"; $collChunks = $this->getDb()->{$collChunkName}; $collChunks->remove(['files_id' => $this->_id]); } $doc = (new \Dsc\Mongo\Collections\Trash())->setCondition('document._id', $this->_id)->getItem(); $doc->remove(); } catch (\Exception $e) { //restore item from trash $doc = (new \Dsc\Mongo\Collections\Trash())->setCondition('document._id', $this->_id)->getItem(); if (!empty($doc)) { $doc->restore(); } } parent::afterDelete(); }