public function testRef()
 {
     ini_set("mongo.cmd", ":");
     $this->object->insert(array("_id" => 123, "hello" => "world"));
     $this->object->insert(array("_id" => 456, "ref" => array(":ref" => "bar", ":id" => 123)));
     $ref = $this->object->findOne(array("_id" => 456));
     $obj = MongoDBRef::get($this->object->db, $ref["ref"]);
     $this->assertNotNull($obj);
     $this->assertEquals("world", $obj["hello"], json_encode($obj));
 }
示例#2
0
 public function insert($a, $options = array())
 {
     try {
         $options = array_merge($options, array('safe' => TRUE));
         return parent::insert($a, $options);
     } catch (MongoCursorException $e) {
         show_error("MongoDB insert failed: {$e->getMessage()}", 500);
     }
 }
 public function testGetDBRef()
 {
     for ($i = 0; $i < 50; $i++) {
         $this->object->insert((object) array('x' => rand()));
     }
     $obj = $this->object->findOne();
     $ref = $this->object->createDBRef($obj);
     $obj2 = $this->object->getDBRef($ref);
     $this->assertNotNull($obj2);
     $this->assertEquals($obj['x'], $obj2['x']);
 }