Beispiel #1
0
 public function batchInsert($a, $options = array())
 {
     try {
         $options = array_merge($options, array('safe' => TRUE));
         return parent::batchInsert($a, $options);
     } catch (MongoCursorException $e) {
         show_error("MongoDB batchInsert failed: {$e->getMessage()}", 500);
     }
 }
 public function testBatchInsert()
 {
     $this->assertTrue($this->object->batchInsert(array('z' => (object) array('foo' => 'bar'))));
     $a = array((object) array("x" => "y"), (object) array("x" => "z"), (object) array("x" => "foo"));
     $this->object->batchInsert($a);
     $this->assertEquals(4, $this->object->count());
     $cursor = $this->object->find(array("x" => array('$exists' => 1)))->sort((object) array("x" => -1));
     $x = $cursor->getNext();
     $this->assertEquals('z', $x['x']);
     $x = $cursor->getNext();
     $this->assertEquals('y', $x['x']);
     $x = $cursor->getNext();
     $this->assertEquals('foo', $x['x']);
 }