本文整理汇总了PHP中Mongo::selectCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP Mongo::selectCollection方法的具体用法?PHP Mongo::selectCollection怎么用?PHP Mongo::selectCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mongo
的用法示例。
在下文中一共展示了Mongo::selectCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
/**
* {@inheritdoc}
*/
public function connect(array $config)
{
$requiredParams = array('hostname', 'db', 'collection');
foreach ($requiredParams as $param) {
if (!isset($config[$param])) {
throw new SetupException('Missing config attribute "' . $param . '"');
}
}
$port = isset($config['port']) ? (int) $config['port'] : 27017;
$mongo = new \Mongo('mongodb://' . $config['hostname'] . ':' . $port);
$this->adapter = $mongo->selectDB($config['db']);
$this->collection = $this->adapter->selectCollection($config['collection']);
return $this;
}
示例2:
/**
* 构造查询
*
* @param Mongo $mongo MongoDB连接
* @param string $db 数据库
* @param string $collection 集合
*/
function __construct(Mongo $mongo, $db, $collection)
{
$this->_dbName = $db;
$this->_collectionName = $collection;
$this->_db = $mongo->selectDB($this->_dbName);
$this->_collection = $mongo->selectCollection($this->_dbName, $this->_collectionName);
}
示例3: testBasic
public function testBasic()
{
$r1 = new MongoRegex("//");
$this->assertEquals($r1->regex, "");
$this->assertEquals($r1->flags, "");
$r2 = new MongoRegex("/foo/bar");
$this->assertEquals($r2->regex, "foo");
$this->assertEquals($r2->flags, "bar");
$r3 = new MongoRegex($r2);
$this->assertEquals($r3->regex, "foo");
$this->assertEquals($r3->flags, "bar");
$stupid_str = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
$rstupid = new MongoRegex("/{$stupid_str}/flagflagflagflagflag");
$this->assertEquals($rstupid->regex, $stupid_str);
$this->assertEquals($rstupid->flags, "flagflagflagflagflag");
$m = new Mongo();
$c = $m->selectCollection('phpunit', 'regex');
$c->drop();
$c->insert(array('x' => 0, 'r1' => $r1));
$c->insert(array('x' => 1, 'r2' => $r2));
$c->insert(array('x' => 2, 'stupid' => $rstupid));
$obj = $c->findOne(array('x' => 0));
$this->assertEquals($obj['r1']->regex, "");
$this->assertEquals($obj['r1']->flags, "");
$obj = $c->findOne(array('x' => 1));
$this->assertEquals($obj['r2']->regex, "foo");
$this->assertEquals($obj['r2']->flags, "bar");
$obj = $c->findOne(array('x' => 2));
$this->assertEquals($obj['stupid']->regex, $stupid_str);
$this->assertEquals($obj['stupid']->flags, "flagflagflagflagflag");
}
示例4: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp()
{
$m = new Mongo();
$this->object = $m->selectCollection('phpunit', 'c');
$this->object->drop();
// $this->object->start = memory_get_usage(true);
}
示例5: 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;
}
示例6: init
/**
* Init 初始化
* @param string $db
* @param string $collection
*/
public static function init($db = '', $collection = '')
{
if (!self::$_mongoDB) {
$config = self::$_config;
$conStr = "mongodb://";
if ($config['user'] && $config['password']) {
$conStr .= "{$config['user']}:{$config['password']}@";
}
$conStr .= "{$config['host']}:{$config['port']}";
$_mongoDB = new Mongo($conStr, array("connect" => false));
if ($db && $collection) {
self::$_mongoDB = $_mongoDB->selectCollection($db, $collection);
} else {
self::$_mongoDB = $_mongoDB->selectCollection(static::$_db, static::$_collection);
}
}
}
示例7: getMongo
/**
* Internal convenience method that returns the instance of the MongoDB Collection
*
* @return \MongoCollection
*/
protected function getMongo()
{
if ($this->mongo === null) {
$mongo = new \Mongo($this->dsn);
list($database, $collection, ) = explode('/', substr(parse_url($this->dsn, PHP_URL_PATH), 1));
$this->mongo = $mongo->selectCollection($database, $collection);
}
return $this->mongo;
}
示例8: setup
function setup()
{
if (PHP_INT_SIZE != 4) {
$this->markTestSkipped("Only for 32 bit platforms");
}
ini_set('mongo.native_long', 0);
ini_set('mongo.long_as_object', 0);
$m = new Mongo();
$this->object = $m->selectCollection("phpunit", "ints");
$this->object->drop();
}
示例9: testDropDB
public function testDropDB()
{
$this->object->connect();
$c = $this->object->selectCollection("temp", "foo");
$c->insert(array('x' => 1));
$this->object->dropDB("temp");
$this->assertEquals($c->findOne(), NULL);
$db = $this->object->selectDB("temp");
$c->insert(array('x' => 1));
$this->object->dropDB($db);
$this->assertEquals($c->findOne(), NULL);
}
示例10: insertarTweetInfo
function insertarTweetInfo($id_tweet, $tweet, $rts, $favs, $fecha_creacion, $usuario, $url_imagen, $followers, $following, $num_tweets)
{
//creamos la conexion con la BD
$mongo = new Mongo();
$db = $mongo->selectDB("TwettsDB");
$c_twettsMovilidad = $mongo->selectCollection("TwettsDB", "twettsMovilidad");
$nuevoTweet = array("ID" => $id_tweet, "TWETT" => $tweet, "RETWETTS" => $rts, "FAVORITOS" => $favs, "FECHA_CREACION" => $fecha_creacion, "USUARIO" => $usuario, "URL_IMAGEN" => $url_imagen, "N_MIS_SEGUIDORES" => $followers, "N_SEGUIDORES" => $following, "N_TWETTS_ENVIADOS" => $num_tweets);
$c_twettsMovilidad->insert($nuevoTweet);
$twettsMovilidad = $c_twettsMovilidad->find();
foreach ($twettsMovilidad as $twett) {
print_r($twett);
}
}
示例11: testGetDBRef
public function testGetDBRef()
{
$c = $this->object->selectCollection('foo');
$c->drop();
for ($i = 0; $i < 50; $i++) {
$c->insert((object) array('x' => rand()), array("safe" => true));
}
$obj = $c->findOne();
$ref = $this->object->createDBRef('foo', $obj);
$obj2 = $this->object->getDBRef($ref);
$this->assertNotNull($obj2);
$this->assertEquals($obj['x'], $obj2['x']);
}
示例12: testConstruct
public function testConstruct()
{
$m = new Mongo("localhost:27017,localhost:27018", false);
$m->pairConnect();
$c = $m->selectCollection("phpunit", "test");
$c->insert(array("foo", "bar"));
$left = new Mongo("localhost:27017");
$left->selectCollection("foo", "bar")->insert(array('x' => 1));
$lerr = $left->lastError();
$right = new Mongo("localhost:27018");
$right->selectCollection("foo", "bar")->insert(array('x' => 1));
$rerr = $right->lastError();
}
示例13: initialize
/**
* Initializes this logger.
*
* @throws sfInitializationException
*
* @param sfEventDispatcher $dispatcher A sfEventDispatcher instance
* @param array $options An array of options.
*
* @return bool
*/
public function initialize(sfEventDispatcher $dispatcher, $options = array())
{
if (!class_exists('Mongo')) {
throw new sfInitializationException('The MongoDB extension is not installed or enabled.');
}
foreach ($this->getRequiredOptions() as $eachOption) {
if (!isset($options[$eachOption])) {
throw new sfInitializationException(sprintf('The required option "%s" is missing.', $eachOption));
}
}
$this->options = array_merge($this->getDefaultOptions(), $options);
if ($this->options['username'] and $this->options['password']) {
$this->handler = new Mongo(sprintf('mongodb://%s:%s@%s:%d/%s', $this->options['username'], $this->options['password'], $this->options['host'], $this->options['port'], $this->options['database']));
} else {
$this->handler = new Mongo(sprintf('mongodb://%s:%d', $this->options['host'], $this->options['port']));
}
if (!empty($this->options['create'])) {
$this->handler->selectDB($this->options['database'])->createCollection($this->options['collection'], $this->options['create']['capped'], $this->options['create']['size'], $this->options['create']['max']);
}
$this->collection = $this->handler->selectCollection($this->options['database'], $this->options['collection']);
return parent::initialize($dispatcher, $this->options);
}
示例14: testMethods
public function testMethods()
{
$m = new Mongo();
$c = $m->selectCollection('phpunit', 'objs4');
$c->drop();
$f = new Foo();
$c->insert($f);
$f->x = 3;
$c->save($f);
$f->y = 7;
$c->update(array('_id' => $f->_id), $f);
$c->remove($f);
}
示例15: getMongo
/**
* Internal convenience method that returns the instance of the MongoDB Collection
*
* @return \MongoCollection
*/
protected function getMongo()
{
if ($this->mongo === null) {
if (preg_match('#^(mongodb://.*)/(.*)/(.*)$#', $this->dsn, $matches)) {
$mongo = new \Mongo($matches[1] . (!empty($matches[2]) ? '/' . $matches[2] : ''));
$database = $matches[2];
$collection = $matches[3];
$this->mongo = $mongo->selectCollection($database, $collection);
} else {
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use MongoDB with an invalid dsn "%s". The expected format is "mongodb://user:pass@location/database/collection"', $this->dsn));
}
}
return $this->mongo;
}