本文整理汇总了PHP中MongoCursor::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCursor::insert方法的具体用法?PHP MongoCursor::insert怎么用?PHP MongoCursor::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCursor
的用法示例。
在下文中一共展示了MongoCursor::insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDead
public function testDead()
{
$this->object->drop();
$this->object->insert(array('x' => 1));
$cursor = $this->object->find();
$this->assertFalse($cursor->dead());
$cursor->next();
$this->assertTrue($cursor->dead());
}
示例2: testExplainReset
public function testExplainReset()
{
$this->object->insert(array("x" => "abc"), array('safe' => true));
$cursor = $this->object->find();
$qp = $cursor->explain();
$info = $cursor->info();
$this->assertTrue(!array_key_exists('$explain', $info['query']));
$this->assertTrue(array_key_exists('$query', $info['query']));
$doc = $cursor->getNext();
$this->assertEquals('abc', $doc['x'], json_encode($doc));
}
示例3: testExceptionHost
public function testExceptionHost()
{
$host = "";
$this->object->insert(array("_id" => 1), array("safe" => true));
try {
$this->object->insert(array("_id" => 1), array("safe" => true));
} catch (MongoCursorException $e) {
$host = $e->getHost();
}
$this->assertEquals("localhost:27017", $host);
}
示例4: testTimeout3
public function testTimeout3()
{
for ($i = 0; $i < 10000; $i++) {
$this->object->insert(array("name" => "joe" . $i, "interests" => array(rand(), rand(), rand())));
}
$cmd = $this->object->db->selectCollection('$cmd');
$query = 'r = 0; cursor = db.c.find(); while (cursor.hasNext()) { x = cursor.next(); for (i=0; i<200; i++) { if (x.name == "joe"+i) { r++; } } } return r;';
$count = 0;
for ($i = 0; $i < 3; $i++) {
$cursor = $cmd->find(array('$eval' => $query))->limit(-1)->timeout(500);
try {
$x = $cursor->getNext();
$this->assertFalse(true, json_encode($x));
} catch (MongoCursorTimeoutException $e) {
$count++;
}
}
$this->assertEquals(3, $count);
$x = $this->object->findOne();
$this->assertNotNull($x);
$this->assertTrue(array_key_exists('name', $x), json_encode($x));
$this->assertTrue(array_key_exists('interests', $x), json_encode($x));
}