/** * Checks whether there is document satisfying the specified condition. * * @param CriteriaInterface $criteria * @return bool */ public function exists(CriteriaInterface $criteria = null) { if ($this->_beforeExists()) { $criteria = $this->sm->apply($criteria); $criteria->decorateWith($this->model); /** * TODO Use as limited fields set as possible here: * Pk Fields, or only id, or fields used as query, still need to investigate */ $cursor = $this->em->getCollection()->find($criteria->getConditions()); $cursor->limit(1); // NOTE: Cannot use count(true) here because of hhvm mongofill compatibility, see: // https://github.com/mongofill/mongofill/issues/86 $exists = $cursor->count() !== 0; Event::trigger($this->model, FinderInterface::EventAfterExists); return $exists; } return false; }
/** * Deletes documents with the specified primary keys. * * **Does not raise beforeDelete event and does not emit signals** * * See {@link find()} for detailed explanation about $condition and $params. * * @param array|CriteriaInterface $criteria query criteria. * @since v1.0 */ public function deleteAll($criteria = null) { $criteria = $this->sm->apply($criteria); $result = $this->getCollection()->remove($criteria->getConditions(), $this->options->getSaveOptions(['justOne' => false])); return $this->_result($result); }