1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-30 17:50:00 +02:00

MongoDB: Small cleanup

This commit is contained in:
Peter Knut
2024-11-10 00:14:21 +01:00
parent ee26735ac6
commit 0933e4e67d
2 changed files with 9 additions and 14 deletions

View File

@@ -213,15 +213,14 @@ if (isset($_GET["mongo"])) {
var $_db, $_db_name; var $_db, $_db_name;
function connect($uri, $options) { function connect($uri, $options) {
$class = 'MongoDB\Driver\Manager';
$this->_link = new $class($uri, $options); $this->_link = new MongoDB\Driver\Manager($uri, $options);
$this->executeCommand('admin', array('ping' => 1)); $this->executeCommand('admin', array('ping' => 1));
} }
function executeCommand($db, $command) { function executeCommand($db, $command) {
$class = 'MongoDB\Driver\Command';
try { try {
return $this->_link->executeCommand($db, new $class($command)); return $this->_link->executeCommand($db, new MongoDB\Driver\Command($command));
} catch (Exception $e) { } catch (Exception $e) {
$this->error = $e->getMessage(); $this->error = $e->getMessage();
return array(); return array();
@@ -338,9 +337,8 @@ if (isset($_GET["mongo"])) {
} }
$limit = min(200, max(1, (int) $limit)); $limit = min(200, max(1, (int) $limit));
$skip = $page * $limit; $skip = $page * $limit;
$class = 'MongoDB\Driver\Query';
try { try {
return new Min_Result($connection->_link->executeQuery("$connection->_db_name.$table", new $class($where, array('projection' => $select, 'limit' => $limit, 'skip' => $skip, 'sort' => $sort)))); return new Min_Result($connection->_link->executeQuery("$connection->_db_name.$table", new MongoDB\Driver\Query($where, array('projection' => $select, 'limit' => $limit, 'skip' => $skip, 'sort' => $sort))));
} catch (Exception $e) { } catch (Exception $e) {
$connection->error = $e->getMessage(); $connection->error = $e->getMessage();
return false; return false;
@@ -351,8 +349,7 @@ if (isset($_GET["mongo"])) {
global $connection; global $connection;
$db = $connection->_db_name; $db = $connection->_db_name;
$where = sql_query_where_parser($queryWhere); $where = sql_query_where_parser($queryWhere);
$class = 'MongoDB\Driver\BulkWrite'; $bulk = new MongoDB\Driver\BulkWrite(array());
$bulk = new $class(array());
if (isset($set['_id'])) { if (isset($set['_id'])) {
unset($set['_id']); unset($set['_id']);
} }
@@ -375,8 +372,7 @@ if (isset($_GET["mongo"])) {
global $connection; global $connection;
$db = $connection->_db_name; $db = $connection->_db_name;
$where = sql_query_where_parser($queryWhere); $where = sql_query_where_parser($queryWhere);
$class = 'MongoDB\Driver\BulkWrite'; $bulk = new MongoDB\Driver\BulkWrite(array());
$bulk = new $class(array());
$bulk->delete($where, array('limit' => $limit)); $bulk->delete($where, array('limit' => $limit));
return $connection->executeBulkWrite("$db.$table", $bulk, 'getDeletedCount'); return $connection->executeBulkWrite("$db.$table", $bulk, 'getDeletedCount');
} }
@@ -384,8 +380,7 @@ if (isset($_GET["mongo"])) {
function insert($table, $set) { function insert($table, $set) {
global $connection; global $connection;
$db = $connection->_db_name; $db = $connection->_db_name;
$class = 'MongoDB\Driver\BulkWrite'; $bulk = new MongoDB\Driver\BulkWrite(array());
$bulk = new $class(array());
if ($set['_id'] == '') { if ($set['_id'] == '') {
unset($set['_id']); unset($set['_id']);
} }
@@ -514,8 +509,7 @@ if (isset($_GET["mongo"])) {
$op = $match[1]; $op = $match[1];
} elseif (preg_match('~^\(date\)(.+)~', $op, $match)) { } elseif (preg_match('~^\(date\)(.+)~', $op, $match)) {
$dateTime = new DateTime($val); $dateTime = new DateTime($val);
$class = 'MongoDB\BSON\UTCDatetime'; $val = new MongoDB\BSON\UTCDatetime($dateTime->getTimestamp() * 1000);
$val = new $class($dateTime->getTimestamp() * 1000);
$op = $match[1]; $op = $match[1];
} }
switch ($op) { switch ($op) {

View File

@@ -42,6 +42,7 @@
"ext-mysql": "*", "ext-mysql": "*",
"ext-pgsql": "*", "ext-pgsql": "*",
"ext-mongo": "*", "ext-mongo": "*",
"ext-mongodb": "*",
"ext-sqlsrv": "*", "ext-sqlsrv": "*",
"ext-mssql": "*", "ext-mssql": "*",
"ext-oci8": "*", "ext-oci8": "*",