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


PHP MongoDB類代碼示例

本文整理匯總了PHP中MongoDB的典型用法代碼示例。如果您正苦於以下問題:PHP MongoDB類的具體用法?PHP MongoDB怎麽用?PHP MongoDB使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: tearDown

 public function tearDown()
 {
     if ($this->db instanceof \MongoDB) {
         $this->db->drop();
     }
     parent::tearDown();
 }
開發者ID:alapini,項目名稱:apigility-3hr-tutorial,代碼行數:7,代碼來源:AuthControllerWithMongoAdapterTest.php

示例2: setUp

 /**
  * @access protected
  */
 protected function setUp()
 {
     $m = new Mongo();
     $db = new MongoDB($m, "phpunit");
     $this->object = $db->selectCollection('c');
     $this->object->drop();
 }
開發者ID:redmeadowman,項目名稱:mongo-php-driver,代碼行數:10,代碼來源:MongoCollectionTest2.php

示例3: get

 /**
  * Fetches the object pointed to by a reference
  * @link http://php.net/manual/en/mongodbref.get.php
  * @static
  * @param MongoDB $db Database to use
  * @param array $ref Reference to fetch
  * @return array|null Returns the document to which the reference refers or null if the document does not exist (the reference is broken)
  */
 public static function get($db, $ref)
 {
     if (!static::isRef($ref)) {
         return null;
     }
     return $db->selectCollection($ref[static::$refKey])->findOne(['_id' => $ref[static::$idKey]]);
 }
開發者ID:RageZBla,項目名稱:mongo-php-adapter,代碼行數:15,代碼來源:MongoDBRef.php

示例4: __construct

 /**
  * Creates new file collections
  *
  * @param mongodb $db - Database.
  * @param string $prefix -
  * @param mixed $chunks -
  */
 public function __construct(MongoDB $db, $prefix = 'fs', $chunks = 'fs')
 {
     $this->db = $db;
     $thisName = $prefix . '.files';
     $this->chunksName = $prefix . '.chunks';
     $this->chunks = $db->selectCollection($this->chunksName);
     parent::__construct($db, $thisName);
 }
開發者ID:Wynncraft,項目名稱:mongofill,代碼行數:15,代碼來源:MongoGridFS.php

示例5: __construct

 public function __construct(\MongoDB $db, $collection_name, array $additional_find_fields = [])
 {
     if (false === is_string($collection_name)) {
         throw new Exception('collection name must be a string');
     }
     $this->collection = $db->selectCollection($collection_name);
     $this->additional_find_fields = $additional_find_fields;
 }
開發者ID:pjullah,項目名稱:repository,代碼行數:8,代碼來源:Repository.php

示例6: exec

 /**
  * Execute a piece of javascript code
  *
  * @param MongoDB $db DB
  * @param string $code javascript code
  * @param array $params javascript function parameters
  * @return array 
  */
 static function exec(MongoDB $db, $code, array $params = array())
 {
     $query = $db->execute($code, $params);
     if (!$query["ok"]) {
         exit("Execute failed:<font color=\"red\">" . $query["errmsg"] . "</font><br/>\n<pre>" . $code . "</pre>");
     }
     return $query["retval"];
 }
開發者ID:buraka1,項目名稱:mlazarov-rockmongo,代碼行數:16,代碼來源:MDb.php

示例7: __construct

 /**
  * Constructor.
  *
  * @param Connection   $connection     Connection used to create Collections
  * @param \MongoDB     $mongoDB        MongoDB instance being wrapped
  * @param EventManager $evm            EventManager instance
  * @param integer      $numRetries     Number of times to retry queries
  * @param callable     $loggerCallable The logger callable
  */
 public function __construct(Connection $connection, $mongoDB, EventManager $evm, $numRetries, $loggerCallable)
 {
     if (!is_callable($loggerCallable)) {
         throw new \InvalidArgumentException('$loggerCallable must be a valid callback');
     }
     parent::__construct($evm, $mongoDB->getDatabaseName());
     $this->loggerCallable = $loggerCallable;
 }
開發者ID:pliashkou,項目名稱:mongodb,代碼行數:17,代碼來源:LoggableDatabase.php

示例8: setUp

 public function setUp()
 {
     parent::setUp();
     $this->mongo = new MongoDB(new \MongoClient('mongodb://localhost:27017'), 'mongo_test', new InMemoryCache());
     $this->collection = $this->mongo->selectCollection('test');
     for ($i = 0; $i < 2; $i++) {
         $this->collection->insert(['foo' => 1]);
     }
 }
開發者ID:nicklasos,項目名稱:MongoCache,代碼行數:9,代碼來源:MongoCollectionTest.php

示例9: __construct

 /**
  * @param Client $client
  * @param \MongoDB|string $database
  */
 public function __construct(Client $client, $database)
 {
     $this->client = $client;
     if ($database instanceof \MongoDB) {
         $this->database = $database;
         $this->databaseName = $database->__toString();
     } else {
         $this->databaseName = $database;
     }
 }
開發者ID:sokil,項目名稱:php-mongo,代碼行數:14,代碼來源:Database.php

示例10: __construct

 public function __construct($host, $port, $name, $username, $password)
 {
     try {
         $client = new \MongoClient("mongodb://{$host}:{$port}");
         $this->db = new \MongoDB($client, $name);
         $this->db->authenticate($username, $password);
     } catch (\MongoException $e) {
         die('Connection failed: ' . $e->getMessage());
     }
 }
開發者ID:OhYea777,項目名稱:Framework,代碼行數:10,代碼來源:MongoDatabase.class.php

示例11: testTest

 public function testTest()
 {
     return;
     $mongo = new MongoDB(new \MongoClient('mongodb://localhost:27017'), 'mongo_test', new Memcache($this->memcache, 1));
     $collection = $mongo->selectCollection('test_memcache');
     $collection->insert(['foo' => 1]);
     $this->assertEquals(1, $collection->count());
     sleep(1);
     $collection->insert(['foo' => 1]);
     $this->assertEquals(2, $collection->count());
 }
開發者ID:nicklasos,項目名稱:MongoCache,代碼行數:11,代碼來源:MemcacheTest.php

示例12: connect

 /**
  * Connects to our database
  */
 public function connect()
 {
     if (!extension_loaded('mongo')) {
         throw new EMongoException(yii::t('yii', 'We could not find the MongoDB extension ( http://php.net/manual/en/mongo.installation.php ), please install it'));
     }
     try {
         $this->_mongo = new MongoClient($this->connectionString, $this->connectOptions);
         $dbname = $this->db;
         $this->_db = $this->_mongo->{$dbname};
         $this->_db->setWriteConcern($this->options['writeConcerns'], $this->options['wTimeoutMS']);
     } catch (Exception $e) {
         throw new EMongoException(yii::t('yii', 'We could not find the MongoDB extension ( http://php.net/manual/en/mongo.installation.php ), please install it'));
     }
 }
開發者ID:blackdragon199154,項目名稱:scryptmail,代碼行數:17,代碼來源:MongoDBConnection.php

示例13: getCollection

 public function getCollection($collName)
 {
     if (!$this->database) {
         throw new Exception\LogicException("Can't select collection as there's no database set");
     }
     return $this->database->selectCollection($collName);
 }
開發者ID:railsphp,項目名稱:ar-mongo,代碼行數:7,代碼來源:Connection.php

示例14: getChannelCollection

 public static function getChannelCollection()
 {
     if (MongoConnector::$db == null) {
         MongoConnector::connect();
     }
     return MongoConnector::$db->selectCollection("channels");
 }
開發者ID:xpyctum,項目名稱:ShogChat,代碼行數:7,代碼來源:MongoConnector.php

示例15: evaluate

 /**
  * Evaluates the constraint for parameter $other. Returns TRUE if the
  * constraint is met, FALSE otherwise.
  *
  * @param mixed $other Value or object to evaluate.
  * @return bool
  */
 public function evaluate($other)
 {
     $query = array('_id' => $other);
     $data = $this->db->selectCollection($this->collection)->findOne($query);
     $this->found = $data[$this->property];
     return ($this->found == $this->expected);
 }
開發者ID:rickyrobinett,項目名稱:morph,代碼行數:14,代碼來源:DocumentPropertyEquals.php


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