当前位置: 首页>>代码示例>>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;未经允许,请勿转载。