/** * 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 testAddToSetEach_KeyExists() { $operator = new Operator(); $operator->addToSetEach('param', array('value1', 'value2')); $operator->addToSetEach('param', array('value3', 'value4')); $this->assertEquals(array('$addToSet' => array('param' => array('$each' => array('value1', 'value2', 'value3', 'value4')))), $operator->toArray()); }