本文整理汇总了PHP中MongoDB::selectCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoDB::selectCollection方法的具体用法?PHP MongoDB::selectCollection怎么用?PHP MongoDB::selectCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB
的用法示例。
在下文中一共展示了MongoDB::selectCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getChannelCollection
public static function getChannelCollection()
{
if (MongoConnector::$db == null) {
MongoConnector::connect();
}
return MongoConnector::$db->selectCollection("channels");
}
示例2: 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);
}
示例3: 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);
}
示例4: 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]);
}
}
示例5: collection
/**
* Retrieves a collection by name.
* @param $name
* @return MongoCollection
*/
public function collection($name)
{
if ($this->collections[$name]) {
return $this->collections[$name];
}
$c = $this->mongo_db->selectCollection($name);
$this->collections[$name] = $c;
return $c;
}
示例6: 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)
{
$documentExists = false;
$query = array('_id' => $other);
$data = $this->db->selectCollection($this->collection)->findOne($query);
if (!empty($data)) {
$documentExists = true;
}
return $documentExists;
}
示例7: _assocQuery
/**
*/
protected function _assocQuery($query, $filters, $parent)
{
foreach ($filters as $val) {
switch ($val['op']) {
case '>':
$query[$val['field']] = array('$gt' => $val['value']);
break;
case '>=':
$query[$val['field']] = array('$gte' => $val['value']);
break;
case '<':
$query[$val['field']] = array('$lt' => $val['value']);
break;
case '<=':
$query[$val['field']] = array('$lte' => $val['value']);
break;
case '=':
$query[$val['field']] = $val['value'];
break;
}
}
if ($parent) {
$query[self::UID] = array('$regex' => preg_quote($parent) . ':*');
}
try {
$cursor = $this->_db->selectCollection(self::MONGO_DATA)->find($query, array(self::UID => true));
$out = array();
foreach ($cursor as $val) {
$out[$val[self::UID]] = strval($val['_id']);
}
} catch (MongoException $e) {
throw new Horde_History_Exception($e);
}
return $out;
}
示例8: import
/**
* Imports data into the current collection
*
* @param string $collection
* @param array $data
* @param string $importMethod Valid options are batchInsert, save, insert, update
*/
public function import($collection, array $data, $importMethod)
{
$coll = $this->mongo->selectCollection($collection);
switch ($importMethod) {
case 'batchInsert':
foreach ($data as &$obj) {
$obj = unserialize($obj);
}
$coll->{$importMethod}($data);
break;
case 'update':
foreach ($data as $obj) {
$obj = unserialize($obj);
if (is_object($obj) && property_exists($obj, '_id')) {
$_id = $obj->_id;
} else {
if (is_array($obj) && isset($obj['_id'])) {
$_id = $obj['_id'];
} else {
continue;
}
}
$coll->{$importMethod}(array('_id' => $_id), $obj);
}
break;
default:
//insert & save
foreach ($data as $obj) {
$coll->{$importMethod}(unserialize($obj));
}
break;
}
}
示例9: 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]]);
}
示例10: setUp
/**
* @access protected
*/
protected function setUp()
{
$m = new Mongo();
$db = new MongoDB($m, "phpunit");
$this->object = $db->selectCollection('c');
$this->object->drop();
}
示例11: getTags
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags()
{
$cmd['mapreduce'] = $this->_options['collection'];
$cmd['map'] = 'function(){
this.t.forEach(
function(z){
emit( z , { count : 1 } );
}
);
};';
$cmd['reduce'] = 'function( key , values ){
var total = 0;
for ( var i=0; i<values.length; i++ )
total += values[i].count;
return { count : total };
};';
$cmd['out'] = array('replace' => 'getTagsCollection');
$res2 = $this->_db->command($cmd);
$res3 = $this->_db->selectCollection('getTagsCollection')->find();
$res = array();
foreach ($res3 as $key => $val) {
$res[] = $key;
}
$this->_db->dropCollection($res2['result']);
return $res;
}
示例12: __get
/**
* Gets a collection
*
* @link http://www.php.net/manual/en/mongocollection.get.php
* @param string $name The next string in the collection name.
* @return MongoCollection
*/
public function __get($name)
{
// Handle w and wtimeout properties that replicate data stored in $readPreference
if ($name === 'w' || $name === 'wtimeout') {
return $this->getWriteConcern()[$name];
}
return $this->db->selectCollection($this->name . '.' . $name);
}
示例13: __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);
}
示例14: purge
/**
* Purges the cache deleting all items within it.
*
* @return boolean True on success. False otherwise.
*/
public function purge()
{
if ($this->isready) {
$this->collection->drop();
$this->collection = $this->database->selectCollection($this->definitionhash);
}
return true;
}
示例15: __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;
}