Sokil\Mongo\Document::delete PHP Method

delete() public method

public delete ( )
    public function delete()
    {
        if ($this->triggerEvent('beforeDelete')->isCancelled()) {
            return $this;
        }
        $status = $this->collection->getMongoCollection()->remove(array('_id' => $this->getId()));
        if (true !== $status && $status['ok'] != 1) {
            throw new \Sokil\Mongo\Exception(sprintf('Delete document error: %s', $status['err']));
        }
        $this->triggerEvent('afterDelete');
        // drop from document's pool
        $this->getCollection()->removeDocumentFromDocumentPool($this);
        return $this;
    }

Usage Example

コード例 #1
0
ファイル: Collection.php プロジェクト: sokil/php-mongo
 /**
  * @deprecated since 1.13. Use Document::delete()
  * @param \Sokil\Mongo\Document $document
  * @return \Sokil\Mongo\Collection
  */
 public function deleteDocument(Document $document)
 {
     $document->delete();
     return $this;
 }