/**
* 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());
}