/** * Find first document and update it * * @param Operator $operator operations with document to update * @param bool $upsert if document not found - create * @param bool $returnUpdated if true - return updated document * * @return null|Document */ public function findAndUpdate(Operator $operator, $upsert = false, $returnUpdated = true) { $mongoDocument = $this->collection->getMongoCollection()->findAndModify($this->expression->toArray(), $operator ? $operator->toArray() : null, $this->fields, array('new' => $returnUpdated, 'sort' => $this->sort, 'upsert' => $upsert)); if (!$mongoDocument) { return null; } return $this->collection->hydrate($mongoDocument, $this->isDocumentPoolUsed()); }
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; }