public function delete($safe = true)
{
if (!$this->isConnected()) {
require_once 'Shanty/Mongo/Exception.php';
throw new Shanty_Mongo_Exception('Can not delete document. Document is not connected to a db and collection');
}
if ($this->isLocked()) {
require_once 'Shanty/Mongo/Exception.php';
throw new Shanty_Mongo_Exception('Can not save documet. Document is locked.');
}
$mongoCollection = $this->_getMongoCollection(true);
// Execute pre delete hook
$this->preDelete();
if (!$this->isRootDocument()) {
$result = $mongoCollection->update($this->getCriteria(), array('$unset' => array($this->getPathToDocument() => 1)), array('safe' => $safe));
} else {
$result = $mongoCollection->remove($this->getCriteria(), array('justOne' => true, 'safe' => $safe));
}
// Execute post delete hook
$this->postDelete();
return $result;
}