insertMultiple() public method

Deprecation: since 1.13 Use Collection::batchInsert()
public insertMultiple ( $rows, $validate = true )
コード例 #1
0
ファイル: CollectionTest.php プロジェクト: sokil/php-mongo
 /**
  * @expectedException \Sokil\Mongo\Exception
  * @expectedExceptionMessage Batch insert error
  */
 public function testInsertMultiple_ErrorInsertingWithUnacknowledgeWrite()
 {
     $this->collectionMock = $this->getMock('\\MongoCollection', array('batchInsert'), array($this->database->getMongoDB(), 'phpmongo_test_collection'));
     $this->collectionMock->expects($this->once())->method('batchInsert')->will($this->returnValue(false));
     $this->collection = new Collection($this->database, $this->collectionMock);
     // insert multiple
     $this->collection->insertMultiple(array(array('a' => 1, 'b' => 2), array('a' => 3, 'b' => 4)));
 }
コード例 #2
0
ファイル: PipelineTest.php プロジェクト: agolomazov/php-mongo
 public function testAggregate_Callable()
 {
     $this->collection->insertMultiple(array(array('order' => 1, 'item' => 1, 'amount' => 110, 'category' => 1), array('order' => 1, 'item' => 2, 'amount' => 120, 'category' => 1), array('order' => 1, 'item' => 3, 'amount' => 130, 'category' => 2), array('order' => 2, 'item' => 1, 'amount' => 210, 'category' => 1), array('order' => 2, 'item' => 2, 'amount' => 220, 'category' => 1), array('order' => 2, 'item' => 3, 'amount' => 230, 'category' => 2)));
     $result = $this->collection->aggregate(function ($pipeline) {
         /* @var $pipeline \Sokil\Mongo\Pipeline */
         $pipeline->match(array('category' => 1))->group(array('_id' => '$order', 'totalAmount' => array('$sum' => '$amount')))->sort(array('_id' => 1));
     });
     $this->assertEquals(array(0 => array('_id' => 1, 'totalAmount' => 230), 1 => array('_id' => 2, 'totalAmount' => 430)), $result);
 }
コード例 #3
0
 public function testPush()
 {
     $this->collection->insertMultiple(array(array("_id" => 1, "item" => "abc", "price" => 10, "quantity" => 2, "date" => new \MongoDate(strtotime("2014-01-01T08:00:00Z"))), array("_id" => 2, "item" => "jkl", "price" => 20, "quantity" => 1, "date" => new \MongoDate(strtotime("2014-02-03T09:00:00Z"))), array("_id" => 3, "item" => "xyz", "price" => 5, "quantity" => 5, "date" => new \MongoDate(strtotime("2014-02-03T09:05:00Z"))), array("_id" => 4, "item" => "abc", "price" => 10, "quantity" => 10, "date" => new \MongoDate(strtotime("2014-02-15T08:00:00Z"))), array("_id" => 5, "item" => "xyz", "price" => 5, "quantity" => 10, "date" => new \MongoDate(strtotime("2014-02-15T09:05:00Z"))), array("_id" => 6, "item" => "xyz", "price" => 5, "quantity" => 5, "date" => new \MongoDate(strtotime("2014-02-15T12:05:10Z"))), array("_id" => 7, "item" => "xyz", "price" => 5, "quantity" => 10, "date" => new \MongoDate(strtotime("2014-02-15T14:12:12Z")))));
     $pipeline = new Pipeline($this->collection);
     $pipeline->group(function ($stage) {
         /* @var $stage \Sokil\Mongo\Pipeline\GroupStage */
         $stage->setId('$item')->push('itemsSold', array('quantity' => '$quantity', 'price' => '$price', 'quantityPrice' => array('$multiply' => array('$quantity', '$price'))));
     });
     $result = $pipeline->aggregate();
     $this->assertEquals('xyz', $result[0]['_id']);
     $this->assertEquals(5, $result[0]['itemsSold'][0]['quantity']);
     $this->assertEquals(5, $result[0]['itemsSold'][0]['price']);
     $this->assertEquals(25, $result[0]['itemsSold'][0]['quantityPrice']);
 }
コード例 #4
0
ファイル: CursorTest.php プロジェクト: agolomazov/php-mongo
 public function testPluck_findAsArray_CompoundField()
 {
     $this->collection->insertMultiple(array(array('field' => array('f1' => 'a1', 'f2' => 'b1')), array('field' => array('f1' => 'a2', 'f2' => 'b2')), array('field' => array('f1' => 'a3', 'f2' => 'b3')), array('field' => array('f1' => 'a4', 'f2' => 'b4'))));
     $this->assertEquals(array('b1', 'b2', 'b3', 'b4'), array_values($this->collection->findAsArray()->pluck('field.f2')));
 }