operator() public method

Create Operator instance to use in update operations
public operator ( ) : Operator
return Operator
Example #1
0
 public function testUpdate()
 {
     // insert
     $this->collection->batchInsert(array(array('a' => 1, 'b' => 1), array('a' => 2, 'b' => 2), array('a' => 3, 'b' => 3)));
     // update
     $batch = new BatchUpdate($this->collection);
     $batch->update(array('a' => 1), array('$set' => array('b' => 'updated1')))->update($this->collection->expression()->where('a', 2), $this->collection->operator()->set('b', 'updated2'))->update(function (Expression $e) {
         $e->where('a', 3);
     }, function (Operator $o) {
         $o->set('b', 'updated3');
     })->execute();
     // test
     $result = $this->collection->findAsArray()->sort(array('a' => 1))->map(function ($data) {
         unset($data['_id']);
         return $data;
     });
     $this->assertEquals(array_values($result), array(array('a' => 1, 'b' => 'updated1'), array('a' => 2, 'b' => 'updated2'), array('a' => 3, 'b' => 'updated3')));
 }
Example #2
0
 public function testUpdateAll_WithUnacknowledgedWriteConcern()
 {
     // get collection
     $this->collection->setUnacknowledgedWriteConcern();
     // create documents
     $d1 = $this->collection->createDocument(array('p' => 1));
     $d1->save();
     $d2 = $this->collection->createDocument(array('p' => 1));
     $d2->save();
     // packet update
     $this->collection->updateAll($this->collection->operator()->set('k', 'v'));
     // test
     foreach ($this->collection->find() as $document) {
         $this->assertArrayHasKey('k', $document->toArray());
     }
 }
Example #3
0
 public function testFindAndUpdate_NoDocumentsFound()
 {
     $document = $this->collection->find()->where('param1', 1)->findAndUpdate($this->collection->operator()->set('newParam', '777'));
     $this->assertNull($document);
 }