Sokil\Mongo\Collection::delete PHP Method

delete() public method

Delete collection
public delete ( ) : Collection
return Collection
    public function delete()
    {
        $status = $this->getMongoCollection()->drop();
        if ($status['ok'] != 1) {
            // check if collection exists
            if ('ns not found' !== $status['errmsg']) {
                // collection exist
                throw new Exception('Error deleting collection ' . $this->getName() . ': ' . $status['errmsg']);
            }
        }
        return $this;
    }

Usage Example

Example #1
0
 public function testCancelOperation_BeforeDelete()
 {
     $document = $this->collection->delete()->createDocument(array('field' => 'value'))->save()->onBeforeDelete(function (\Sokil\Mongo\Event $event, $eventName, $dispatcher) {
         $event->cancel();
     })->delete();
     $this->assertEquals(1, $this->collection->count());
 }
All Usage Examples Of Sokil\Mongo\Collection::delete