MongoDB: Alter indexes

This commit is contained in:
Jakub Vrana 2014-01-11 21:08:57 -08:00
parent 91bb94eda6
commit 9edfe6d1ff
2 changed files with 28 additions and 1 deletions

View file

@ -245,6 +245,7 @@ if (isset($_GET["mongo"])) {
$return[$index["name"]] = array(
"type" => ($index["name"] == "_id_" ? "PRIMARY" : ($index["unique"] ? "UNIQUE" : "INDEX")),
"columns" => array_keys($index["key"]),
"lengths" => array(),
"descs" => $descs,
);
}
@ -309,6 +310,32 @@ if (isset($_GET["mongo"])) {
return true;
}
function alter_indexes($table, $alter) {
global $connection;
foreach ($alter as $val) {
list($type, $name, $set) = $val;
if ($set == "DROP") {
$return = $connection->_db->command(array("deleteIndexes" => $table, "index" => $name));
} else {
$columns = array();
foreach ($set as $column) {
$column = preg_replace('~ DESC$~', '', $column, 1, $count);
$columns[$column] = ($count ? -1 : 1);
}
$return = $connection->_db->selectCollection($table)->ensureIndex($columns, array(
"unique" => ($type == "UNIQUE"),
"name" => $name,
//! "sparse"
));
}
if ($return['errmsg']) {
$connection->error = $return['errmsg'];
return false;
}
}
return true;
}
function last_id() {
global $connection;
return $connection->last_id;

View file

@ -1,5 +1,5 @@
Adminer 4.0.3-dev:
MongoDB: insert, truncate
MongoDB: insert, truncate, indexes
SimpleDB, MongoDB: insert more fields at once
Adminer 4.0.2 (released 2014-01-11):