selectCollection() публичный Метод

Gets a database collection
public selectCollection ( string $db, string $collection ) : MongoCollection
$db string - The database name.
$collection string - The collection name.
Результат MongoCollection - Returns a new collection object.
Пример #1
0
 protected function getCollection()
 {
     if (!$this->coll) {
         $this->coll = $this->mongoClient->selectCollection($this->dbName, $this->collName);
     }
     return $this->coll;
 }
Пример #2
0
 /**
  * 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
0
 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
0
 /**
  * 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
0
 /**
  * @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
0
 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
0
 /**
  * @see MongoClient#selectCollection
  */
 public function selectCollection($db, $collection = null)
 {
     if (empty($db)) {
         $db = $this->dbname;
     }
     return parent::selectCollection($db, $collection);
 }
Пример #8
0
 /**
  * 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;
 }
 /**
  * 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
0
 /**
  * @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
0
 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
0
 /**
  * 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
0
 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
0
Файл: Mongo.php Проект: ud223/yj
 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
0
 /**
  * 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);
     }
 }
Пример #16
0
 private function __construct($name)
 {
     list($db, $table) = explode('.', $name);
     if (array_key_exists($db, self::$config)) {
         $config = self::$config[$db];
         if (array_key_exists('prefix', $config) && $config['prefix']) {
             $table = $config['prefix'] . $table;
         }
         if ($config['driver'] === 'mongo') {
             $mongoClient = new \MongoClient($config['server'], $config['options']);
             $this->collection = $mongoClient->selectCollection($config['db'], $table);
         } elseif ($config['driver'] === 'pdo') {
             $pdo = new \PDO($config['dsn'], $config['username'], $config['passwd'], $config['options']);
             $this->collection = new \Boofw\Phpole\Database\Pdo\Collection($pdo, $table);
         } else {
             throw new AppException('Database driver <' . $config['driver'] . '> not found!');
         }
     } else {
         throw new AppException('Database handle <' . $name . '> not found!');
     }
 }
Пример #17
0
 /**
  * Initialize the internal
  *
  * @return \MongoClient
  */
 protected function initMongo()
 {
     if (!empty($this->connection)) {
         return $this->connection;
     }
     $options = $this->getOptions();
     $dsn = $options->dsn;
     $dbname = $options->dbname;
     $collection = $options->collection;
     if (empty($dsn) || empty($dbname) || empty($collection)) {
         throw new Exception\InvalidArgumentException('The "dsn", "dbname", "collection" configurations are missing', 2);
     }
     $this->namespace = $options->getNamespace();
     $_options = $options->mongoOptions;
     if (!class_exists('\\MongoClient')) {
         $this->connection = new \Mongo($dsn, $_options);
     } else {
         $this->connection = new \MongoClient($dsn, $_options);
     }
     $this->db = $this->connection->selectDB($dbname);
     $this->collection = $this->connection->selectCollection($this->db, $collection);
 }
Пример #18
0
rder-color: #432719"> Login </a>
                <?php 
}
?>
</p>
        <div id="page-content-wrapper">
            
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12"><center><h2 style = "color: #5CADFF; font-size: \      
15px">Lost & Found</h2></center>
                <hr />  
                                              <?php 
$connection = new MongoClient();
$db = $connection->selectDB("tuftstuff");
$collection = $connection->selectCollection($db, "Clubs");
$cursor = $collection->find(array('Type' => 'Lost & Found'));
foreach ($cursor as $doc) {
    //echo "$id: ";
    //var_dump( $collection );
    echo $doc["Type"] . ": " . $doc["Title"] . "<br>";
    echo "Location: " . $doc["Location"] . "<br>";
    echo "Time: " . $doc["Time"] . "<br>";
    echo "Description: " . $doc["Description"] . "<br>";
    echo " " . "<br>";
}
?>
    <hr />
                    </div>
                </div>
            </div>
Пример #19
0
 public function updateCase($caseid)
 {
     $m = new MongoClient('mongoHost');
     $collection = $m->selectCollection('Desk', 'cases_that_begin_with_q');
     $options = array("upsert" => true);
     $find = array('id' => $caseid);
     $newdata = array('$set' => array("external_id" => 'cookie monsters trashcan', "description" => 'Friday July1st cookie monster was part of the help desk.'));
     $collection->update($find, $newdata, $options);
 }
Пример #20
0
 /**
  * @param array $log
  * @param $identifier
  *
  * @return array|bool
  */
 public function write(array $log, $identifier)
 {
     $this->collection = $this->client->selectCollection($this->db, $identifier);
     return $this->collection->insert(array('start' => $log['start'], 'end' => $log['end'], 'duration' => $log['duration'], 'memory' => $log['memory'], 'arguments' => $log['arguments']));
 }
Пример #21
0
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
$result = curl_exec($curl_handle);
//print_r($result);
$resultDocument = json_decode($result, true);
$resultDocument['elastic_id'] = $resultDocument['_id'];
unset($resultDocument['_id']);
$resultDocument['filename'] = $orgFilename;
$resultDocument['interaction'] = $json['interaction'];
if (isset($json['language'])) {
    $resultDocument['language'] = $json['language'];
}
if (isset($json['demographics'])) {
    $resultDocument['demographics'] = $json['demographics'];
}
$resultDocument['date'] = date('c', $time);
$resultDocument['date2'] = date('Y-m-d H:i:s', $time);
$resultDocument['_timestamp'] = $time;
$mongoClient = new \MongoClient('mongodb://' . $ip);
//$mongoClient = new \MongoClient('mongodb://'.$ip);
$elasticCollection = $mongoClient->selectCollection('AIVD', 'elastic');
$elasticCollection->ensureIndex(array('elastic_id' => 1));
$elasticCollection->ensureIndex(array('filename' => 1));
$elasticCollection->ensureIndex(array('_type' => 1));
//fputcsv($df, array($resultDocument['elastic_id'], $filename, strip_tags($json['interaction']['content']), $json['language']['tag']), ';');
$elasticCollection->insert($resultDocument);
unlink($filename);
Пример #22
0
<?php

$mongo = new MongoClient('mongodb://*****:*****@ds052827.mongolab.com:52827/miblog');
$db = $mongo->selectDB("miblog");
$c_categoria = $mongo->selectCollection("miblog", "categoria");
/////////////////////////////////
### RootNetworking; Código NO vulnerable a XSS/Html Injection/Seguridad ALTA
/////////////////////////////////
require_once 'seguridad/class.inputfilter.php';
$filtro = new InputFilter();
$_POST = $filtro->process($_POST);
////////////////////////////////////////
/////////////////////////
$nameCategoria = htmlspecialchars(addslashes(stripslashes(strip_tags(trim($_POST['categoria'])))));
$nuevaCategoria = array("categoria" => $nameCategoria);
$c_categoria->insert($nuevaCategoria);
header("Refresh: 0;url=categorias.php?mensaje=2");
?>

Пример #23
0
{
    $query = $db->query('SELECT * from user where uid = ' . $uid, PDO::FETCH_ASSOC);
    return $query->fetch($query);
}
if (isset($_GET['insert'])) {
    $minUid = get_max_uid($mysqlObject);
    $description = str_repeat('A', 900);
    $mongoObject->selectDB('tjut');
    for ($i = 1; $i <= 1000; ++$i) {
        $uid = $i + $minUid;
        $username = '******' . $uid;
        $desc = $username . $description;
        //MySQL插入
        $mysqlObject->exec('INSERT INTO user(username,description) values(\'' . $username . '\',\'' . $desc . '\');');
        //Mongo写插入成功
        $mongoObject->selectCollection('tjut', 'user')->insert(['uid' => $uid, 'username' => $username, 'description' => $desc]);
    }
    echo get_max_uid($mysqlObject), "\n";
} else {
    $maxUid = get_max_uid($mysqlObject);
    $cacheTime = 0;
    $dbTime = 0;
    $redisObject->open('127.0.0.1', 22100);
    for ($i = 0; $i < 1000; ++$i) {
        $uid = rand(1, $maxUid);
        $cacheValue = $redisObject->get($uid);
        if (empty($cacheValue)) {
            $user = get_user($mysqlObject, $uid);
            $redisObject->set($uid, serialize($user));
            ++$dbTime;
        } else {
Пример #24
0
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php 
session_start();
$user = $_SESSION['user'];
if (!$user) {
    header("Location: ../error");
}
//TODO
//Pull list of videos within last week based on classes in users profile
$conn = new MongoClient("mongodb://127.0.0.1:27017");
if ($conn) {
    $videos = $conn->selectCollection("project", "videos");
    $user_classes = $_SESSION['classes'];
    $announcements = array();
    foreach ($user_classes as $c) {
        $query = array('class' => $c);
        $result = $videos->find($query);
        foreach ($result as $res) {
            array_push($announcements, $res);
        }
    }
}
?>

<!-- Header -->
<nav class="navbar navbar-ambush-background">
  <div class="container-fluid">
Пример #25
0
 /**
  * @param string $name
  * @return \MongoCollection
  */
 protected function getCollection($name = 'test')
 {
     $client = new \MongoClient();
     return $client->selectCollection('mongo-php-adapter', $name);
 }
Пример #26
0
 /**
  * Returns the mongo collection with the parameters setted in constructor
  *
  * @return \MongoCollection
  */
 public function getCollection()
 {
     $cnx = new \MongoClient('mongodb://' . $this->paramValid['server']);
     return $cnx->selectCollection($this->paramValid['database'], $this->paramValid['collection']);
 }
Пример #27
0
    <body>

    <?php 
session_unset();
session_start();
$_SESSION['user_exists'] = false;
if ($_POST) {
    $fname = $_POST["fname"];
    $lname = $_POST["lname"];
    $role = $_POST["userrole"];
    $user = $_POST["user"];
    $pass = $_POST["pass"];
    $conn = new MongoClient("mongodb://127.0.0.1:27017");
    if ($conn) {
        $users = $conn->selectCollection("project", "users");
        $options = array('safe' => true, 'fsync' => true, 'timeout' => 10000);
        $searchuser = array('user' => $user);
        $checkexisting = $users->find($searchuser, $options);
        if ($checkexisting->count() == 0) {
            $newuser = array('user' => $user, 'pass' => $pass, 'fname' => $fname, 'lname' => $lname, 'permission' => $role, 'clist' => array());
            $result = $users->insert($newuser, $options);
            if ($result["ok"]) {
                $_SESSION['fname'] = $fname;
                $_SESSION['lname'] = $lname;
                $_SESSION['user'] = $user;
                $_SESSION['role'] = $role;
                $_SESSION['pass'] = $pass;
                $_SESSION['classes'] = array();
                header("Location: ../home/");
            }
 function ledger()
 {
     if ($this->RequestHandler->isAjax()) {
         $this->layout = 'blank';
     } else {
         $this->layout = 'session';
     }
     $this->ath();
     $this->check_user_privilages();
     $s_role_id = $this->Session->read('hm_role_id');
     $s_society_id = $this->Session->read('hm_society_id');
     $s_user_id = $this->Session->read('hm_user_id');
     $this->set('s_role_id', $s_role_id);
     $m = new MongoClient();
     $collection = $m->selectCollection('accounts', 'ledger_account');
     $cursor = $collection->find();
     $this->loadmodel('ledger_account');
     $conditions = array('$or' => array(array('society_id' => $s_society_id), array('society_id' => 0)));
     $cursor1 = $this->ledger_account->find('all', array('conditions' => $conditions));
     $this->set('cursor1', $cursor1);
     $this->loadmodel('ledger_sub_account');
     $conditions = array("society_id" => $s_society_id);
     $cursor2 = $this->ledger_sub_account->find('all', array('conditions' => $conditions));
     $this->set('cursor2', $cursor2);
     $result_financial_year = $this->requestAction(array('controller' => 'Fns', 'action' => 'financial_year_current_open'));
     $from = $result_financial_year[0]['financial_year']['from'];
     $to = $result_financial_year[0]['financial_year']['to'];
     $this->set('from', $from);
     $this->set('to', $to);
 }
Пример #29
0
<?php

$mongo = new MongoClient('mongodb://*****:*****@ds052827.mongolab.com:52827/miblog');
$db = $mongo->selectDB("miblog");
$c_favoritos = $mongo->selectCollection($db, "favorito");
/////////////////////////////////
require_once 'seguridad/class.inputfilter.php';
$filtro = new InputFilter();
$_POST = $filtro->process($_POST);
////////////////////////////////////////
$id = htmlspecialchars(addslashes(stripslashes(strip_tags(trim($_POST['id'])))));
$titulo = htmlspecialchars(addslashes(stripslashes(strip_tags(trim($_POST['titulo'])))));
$categoria = htmlspecialchars(addslashes(stripslashes(strip_tags(trim($_POST["categoria"])))));
$id = htmlspecialchars(addslashes(stripslashes(strip_tags(trim($_POST["id"])))));
$descripcion = htmlspecialchars(addslashes(stripslashes(strip_tags(trim($_POST['descripcion'])))));
$url = htmlspecialchars(addslashes(stripslashes(strip_tags(trim($_POST['url'])))));
////////////////////////////////////
$condicion = array("_id" => new MongoId($id));
$modFavorito = array("titulo" => $titulo, "categoria" => $categoria, "descripcion" => $descripcion, "url" => $url);
$c_favoritos->update($condicion, $modFavorito);
header("Refresh: 0;url=principal.php?mensaje=3");
Пример #30
0
 private function getMongoCollection()
 {
     $connString = 'mongodb://' . \Config::get('database.connections.mongodb.host') . ':' . \Config::get('database.connections.mongodb.port');
     $client = new \MongoClient($connString);
     $mongoCollection = $client->selectCollection(\Config::get('database.connections.mongodb.database'), 'users');
     return $mongoCollection;
 }