當前位置: 首頁>>代碼示例>>PHP>>正文


PHP MongoCursor::findOne方法代碼示例

本文整理匯總了PHP中MongoCursor::findOne方法的典型用法代碼示例。如果您正苦於以下問題:PHP MongoCursor::findOne方法的具體用法?PHP MongoCursor::findOne怎麽用?PHP MongoCursor::findOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MongoCursor的用法示例。


在下文中一共展示了MongoCursor::findOne方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testOverwrite

 public function testOverwrite()
 {
     $fh1 = fopen('tests/somefile', 'r');
     $fh2 = fopen('mongo.c', 'r');
     $this->object->storeFile($fh1, array('_id' => 1));
     $this->object->storeFile($fh2, array('_id' => 1));
     $file = $this->object->findOne();
     $this->assertEquals(129, $file->file['length'], json_encode($file->file));
 }
開發者ID:redmeadowman,項目名稱:mongo-php-driver,代碼行數:9,代碼來源:MongoGridFSTest.php

示例2: testMD5

 public function testMD5()
 {
     $mid = $this->object->storeFile("mongo.c");
     $gid = $this->object->storeFile("gridfs.c");
     $mongo = $this->object->findOne(array("_id" => $mid));
     $gridfs = $this->object->findOne(array("_id" => $gid));
     $this->assertNotEquals($mongo->file['md5'], $gridfs->file['md5']);
     $this->assertEquals($mongo->file['md5'], md5(file_get_contents("mongo.c")));
     $this->assertEquals($gridfs->file['md5'], md5(file_get_contents("gridfs.c")));
 }
開發者ID:petewarden,項目名稱:mongo-php-driver,代碼行數:10,代碼來源:MongoGridFSTest.php

示例3: 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));
 }
開發者ID:kph11,項目名稱:mongo-php-driver,代碼行數:23,代碼來源:SlowTests.php

示例4: test__construct4

 /**
  * @expectedException MongoException
  */
 public function test__construct4()
 {
     $this->object->findOne(array(), array("id", 123));
 }
開發者ID:redmeadowman,項目名稱:mongo-php-driver,代碼行數:7,代碼來源:MongoCursorTest.php

示例5: testEmpty

 public function testEmpty() {
     $this->object->storeFile('tests/empty');
     $file = $this->object->findOne();
     $this->assertEquals(0, $file->file['length']);
 }
開發者ID:neurodrone,項目名稱:mongo-php-driver,代碼行數:5,代碼來源:MongoGridFSTest.php


注:本文中的MongoCursor::findOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。