/** create new collection **/ public function doNewCollection() { $this->db = xn("db"); $this->name = trim(xn("name")); $this->isCapped = xi("is_capped"); $this->size = xi("size"); $this->max = xi("max"); if ($this->isPost()) { $db = $this->_mongo->selectDB($this->db); MCollection::createCollection($db, $this->name, array("capped" => $this->isCapped, "size" => $this->size, "max" => $this->max)); $this->message = "New collection is created. <a href=\"?action=collection.index&db={$this->db}&collection={$this->name}\">[GO »]</a>"; //add index if (!$this->isCapped) { $db->selectCollection($this->name)->ensureIndex(array("_id" => 1)); } } $this->display(); }
/** collection properties **/ public function doCollectionProps() { $this->db = xn("db"); $this->collection = xn("collection"); $ret = $this->_mongo->selectDB($this->db)->selectCollection("system.namespaces")->findOne(array("name" => $this->db . "." . $this->collection)); $this->isCapped = 0; $this->size = 0; $this->max = 0; if (isset($ret["options"]["capped"])) { $this->isCapped = $ret["options"]["capped"]; } if (isset($ret["options"]["size"])) { $this->size = $ret["options"]["size"]; } if (isset($ret["options"]["max"])) { $this->max = $ret["options"]["max"]; } if ($this->isPost()) { $this->isCapped = xi("is_capped"); $this->size = xi("size"); $this->max = xi("max"); //rename current collection $bkCollection = $this->collection . "_rockmongo_bk_" . uniqid(); $this->ret = $this->_mongo->selectDB($this->db)->execute('function (coll, newname, dropExists) { db.getCollection(coll).renameCollection(newname, dropExists);}', array($this->collection, $bkCollection, true)); if (!$this->ret["ok"]) { $this->error = "There is something wrong:<font color=\"red\">{$this->ret['errmsg']}</font>, please refresh the page to try again."; $this->display(); return; } //create new collection $db = $this->_mongo->selectDB($this->db); MCollection::createCollection($db, $this->collection, array("capped" => $this->isCapped, "size" => $this->size, "max" => $this->max)); //copy data to new collection if (!$this->_copyCollection($db, $bkCollection, $this->collection, true)) { //try to recover $this->ret = $db->execute('function (coll, newname, dropExists) { db.getCollection(coll).renameCollection(newname, dropExists);}', array($bkCollection, $this->collection, true)); $this->error = "There is something wrong:<font color=\"red\">{$ret['errmsg']}</font>, please refresh the page to try again."; $this->display(); return; } //drop current collection $db->dropCollection($bkCollection); } $this->display(); }