本文整理汇总了PHP中MongoClient::selectCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoClient::selectCollection方法的具体用法?PHP MongoClient::selectCollection怎么用?PHP MongoClient::selectCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoClient
的用法示例。
在下文中一共展示了MongoClient::selectCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCollection
protected function getCollection()
{
if (!$this->coll) {
$this->coll = $this->mongoClient->selectCollection($this->dbName, $this->collName);
}
return $this->coll;
}
示例2: getCollection
/**
* Return the mongo collection with given name
*
* @param $name
* @return \MongoCollection
*/
protected function getCollection($name)
{
if (!$this->db) {
global $config;
$this->setDb(MongoProvider::getClient($config['db']['host'], array()));
}
return $this->db->selectCollection('shortener', 'links');
}
示例3: __construct
public function __construct(\MongoClient $mongoClient, $database, $collection)
{
$this->setMongoClient($mongoClient);
$this->setDatabase($database);
$this->setCollection($collection);
$this->mongoCollection = $this->mongoClient->selectCollection($this->database, $this->collection);
$this->mongoCollection->ensureIndex(array('expires' => 1), array('expireAfterSeconds' => 0));
}
示例4: setUp
/**
* Setup performed prior to each test method
*
* @return void
*/
public function setUp()
{
if (!extension_loaded('mongo')) {
$this->markTestSkipped('Zend\\Session\\SaveHandler\\MongoDB tests are not enabled due to missing Mongo extension');
}
$this->options = new MongoDBOptions(array('database' => 'zf2_tests', 'collection' => 'sessions'));
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? '\\Mongo' : '\\MongoClient';
$this->mongo = new $mongoClass();
$this->mongoCollection = $this->mongo->selectCollection($this->options->getDatabase(), $this->options->getCollection());
}
示例5: __construct
/**
* @param array $injectors
*/
public function __construct(array $injectors = array())
{
parent::__construct($injectors);
if (!$this->injectors['client']) {
$this->injectors['client'] = new \MongoClient($this->injectors['dsn'], $this->injectors['options']);
}
// Set client and collection
$this->client = $this->injectors['client'];
$this->collection = $this->client->selectCollection($this->injectors['database'], $this->injectors['collection']);
}
示例6: __construct
public function __construct($server = 'mongodb://localhost:27017', $db = 'phpconsole', $collection = 'phpconsole')
{
$this->mongoClient = new \MongoClient($server);
if (!$this->mongoClient) {
throw new \Exception('Unable to connect to MongoDB server');
}
$this->mongoCollection = $this->mongoClient->selectCollection($db, $collection);
if (!$this->mongoCollection) {
throw new \Exception('Unable to get collection');
}
$this->mongoCollection->ensureIndex(array('expireAt' => 1), array('background' => true, 'name' => 'TTL', 'expireAfterSeconds' => 0));
}
示例7: selectCollection
/**
* @see MongoClient#selectCollection
*/
public function selectCollection($db, $collection = null)
{
if (empty($db)) {
$db = $this->dbname;
}
return parent::selectCollection($db, $collection);
}
示例8: getCollection
/**
* Return a "MongoCollection" instance.
*
* @return \MongoCollection
*/
private function getCollection()
{
if (null === $this->collection) {
$this->collection = $this->mongo->selectCollection($this->options['database'], $this->options['collection']);
}
return $this->collection;
}
示例9: getCollection
/**
* Get mongo db stream collection
*
* @return \MongoCollection
*/
private function getCollection()
{
if (null === $this->collection) {
$this->collection = $this->mongoClient->selectCollection($this->dbName, $this->streamCollectionName);
$this->collection->setReadPreference(\MongoClient::RP_PRIMARY);
}
return $this->collection;
}
示例10: getMongoCollection
/**
* @return \MongoCollection
*/
private function getMongoCollection()
{
// connect to the database
if (!$this->mongoCollection) {
$mongoClient = new \MongoClient($this->server);
$this->mongoCollection = $mongoClient->selectCollection($this->database, $this->collection);
}
return $this->mongoCollection;
}
示例11: lastpage
function lastpage($userid)
{
$m = new MongoClient();
$collection = $m->selectCollection('thefacebook', 'log');
$cursor = $collection->find(array('userid' => $userid));
$cursor->sort(array('timestamp' => -1))->limit(2);
$records = iterator_to_array($cursor);
return $records[1]['page'];
}
示例12: __construct
/**
* Create a new cursor
* @link http://www.php.net/manual/en/mongocursor.construct.php
* @param \MongoClient $connection Database connection.
* @param string $ns Full name of database and collection.
*/
public function __construct(\MongoClient $connection, $ns)
{
$this->connection = $connection;
$this->ns = $ns;
$nsParts = explode('.', $ns);
$dbName = array_shift($nsParts);
$collectionName = implode('.', $nsParts);
$this->db = $connection->selectDB($dbName)->getDb();
if ($collectionName) {
$this->collection = $connection->selectCollection($dbName, $collectionName)->getCollection();
}
}
示例13: GetVehicle
public function GetVehicle($params)
{
if (mb_strlen($params->Vehicle->RegistrationNumber) < 2) {
return (object) ['VehicleList' => []];
}
$conn = new MongoClient(sprintf('mongodb://%s:%s@%s', MDB_USER, MDB_PASSWORD, MDB_HOST));
$mtVehicle = $conn->selectCollection(MDB_DATABASE, 'Vehicle');
$qsGetVehicle = ['A07' => ['$regex' => '.*', '$options' => 'i']];
$qsGetVehicle = ['A07' => 'Л8195ГО'];
$mCursor = $mtVehicle->find($qsGetVehicle);
$vehicles = [];
foreach ($mCursor as $mRecord) {
array_push($vehicles, ['RegistrationNumber' => $mRecord['A07'], 'Brand' => 'не указан', 'Model' => 'не указана', 'Color' => 'не указан', 'OwnerFirstName' => $mRecord['IMA'], 'OwnerPatronymic' => $mRecord['A28'], 'OwnerLastName' => $mRecord['A26'], 'OwnerBirthday' => $mRecord['A29'], 'ProductionYear' => $mRecord['A12'], 'OwnerRegionCode' => $mRecord[''], 'OwnerCity' => $mRecord['A35'], 'OwnerStreet' => $mRecord['A36'], 'OwnerHouse' => $mRecord['A37'], 'OwnerBuilding' => $mRecord['A38'], 'OwnerApartment' => $mRecord['A39'], 'VIN' => $mRecord['VIN']]);
}
return (object) ['VehicleList' => $vehicles];
}
示例14: open
public function open($save_path, $name)
{
$result = false;
try {
$mongo = new MongoClient($this->_options['mongo']['server']);
$this->_session = $mongo->selectCollection($this->_options['mongo']['dbname'], 'Session');
} catch (Exception $e) {
if (APPLICATION_ENV != 'production') {
echo "Mongo session start fails: " . $e->getMessage();
exit;
} else {
throw $e;
}
}
if ($this->_session) {
$result = true;
}
return $result;
}
示例15: __construct
/**
* Creates a new cursor
*/
public function __construct()
{
$arguments = func_get_args();
if (!empty($arguments) && $arguments[0] instanceof \MongoCursor) {
$this->_cursor = $arguments[0];
$info = $this->_cursor->info();
list($dbName, $collectionName) = explode('.', $info['ns'], 2);
if (!isset($arguments[1]) || !$arguments[1] instanceof Collection) {
throw new \RuntimeException('Modomo\\MongoCursor::__construct() expects parameter 2 to be of type Modomo\\Adapters\\MongoCollection');
}
$this->_collection = $arguments[1];
} else {
$class = new \ReflectionClass('\\MongoCursor');
$this->_cursor = $class->newInstanceArgs($arguments);
$info = $this->_cursor->info();
list($dbName, $collectionName) = explode('.', $info['ns'], 2);
$conn = new MongoClient($arguments[0]);
$this->_collection = $conn->selectCollection($dbName, $collectionName);
}
}