]> git.joonet.de Git - adminer.git/commitdiff
MongoDB: Alter indexes
authorJakub Vrana <jakub@vrana.cz>
Sun, 12 Jan 2014 05:08:57 +0000 (21:08 -0800)
committerJakub Vrana <jakub@vrana.cz>
Sun, 12 Jan 2014 05:08:57 +0000 (21:08 -0800)
adminer/drivers/mongo.inc.php
changes.txt

index c10aca9be770f614213331a797887902d693d869..ba9d67e0adab564ee0e2476cdebe306c4290c9e5 100644 (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;
index 101be61cabb0b683d8008e7722179a8c9f600b18..003944a1e64b3ad100bcdf4e68a46e4c3f513245 100644 (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):