本文整理汇总了PHP中Mongo::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Mongo::insert方法的具体用法?PHP Mongo::insert怎么用?PHP Mongo::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mongo
的用法示例。
在下文中一共展示了Mongo::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRef
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: insert
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);
}
}
示例3: testGetDBRef
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']);
}