Example #1
0
 /** 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 &raquo;]</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();
 }
Example #3
0
 /** create a collection index **/
 public function doCreateIndex()
 {
     $this->db = x("db");
     $this->collection = xn("collection");
     $this->nativeFields = MCollection::fields($this->_mongo->selectDB($this->db), $this->collection);
     if ($this->isPost()) {
         $db = new MongoDB($this->_mongo, $this->db);
         $collection = $this->_mongo->selectCollection($db, $this->collection);
         $fields = xn("field");
         if (!is_array($fields)) {
             $this->message = "Index contains one field at least.";
             $this->display();
             return;
         }
         $orders = xn("order");
         $attrs = array();
         foreach ($fields as $index => $field) {
             $field = trim($field);
             if (!empty($field)) {
                 $attrs[$field] = $orders[$index] == "asc" ? 1 : -1;
             }
         }
         if (empty($attrs)) {
             $this->message = "Index contains one field at least.";
             $this->display();
             return;
         }
         //if is unique
         $options = array();
         if (x("is_unique")) {
             $options["unique"] = 1;
             if (x("drop_duplicate")) {
                 $options["dropDups"] = 1;
             }
         }
         $options["background"] = 1;
         $options["safe"] = 1;
         //name
         $name = trim(xn("name"));
         if (!empty($name)) {
             $options["name"] = $name;
         }
         $collection->ensureIndex($attrs, $options);
         $this->redirect("collection.collectionIndexes", array("db" => $this->db, "collection" => $this->collection));
     }
     $this->display();
 }
Example #4
0
            ?>
						| GridFS: <a href="<?php 
            h(url("collection.downloadFile", array("db" => $db, "collection" => $collection, "id" => rock_id_string($row["_id"]))));
            ?>
">Download</a> <a href="<?php 
            $criteria = null;
            if ($this->last_format == "json") {
                $criteria = '{
	"files_id": ' . ($row["_id"] instanceof MongoId ? "ObjectId(\"" . addslashes($row["_id"]->__toString()) . "\")" : "\"" . addslashes($row["_id"]) . "\"") . '
}';
            } else {
                $criteria = 'array(
	"files_id" => ' . ($row["_id"] instanceof MongoId ? "new MongoId(\"" . addslashes($row["_id"]->__toString()) . "\")" : "\"" . addslashes($row["_id"]) . "\"") . '
)';
            }
            h(url("collection.index", array("db" => $db, "collection" => MCollection::chunksCollection($collection), "criteria" => $criteria)));
            ?>
">Chunks</a>
						<?php 
        }
        ?>
					</div>	
					
					<!-- display record -->
					<div id="text_<?php 
        h($index);
        ?>
" style="max-height:150px;overflow-y:hidden;width:99%" ondblclick="expandText('<?php 
        h($index);
        ?>
');" class="record_row" record_id="<?php 
Example #5
0
 /** create a collection index **/
 public function doCreate2DIndex()
 {
     $this->db = x("db");
     $this->collection = xn("collection");
     $this->nativeFields = MCollection::fields($this->_mongo->selectDB($this->db), $this->collection);
     if ($this->isPost()) {
         $db = $this->_mongo->selectDB($this->db);
         $collection = $this->_mongo->selectCollection($db, $this->collection);
         $attrs = array();
         //Location Field
         $locationField = trim(xn("location_field"));
         $attrs[$locationField] = "2d";
         //Other Fields
         $fields = xn("field");
         if (!is_array($fields)) {
             $this->message = "Index contains one field at least.";
             $this->display();
             return;
         }
         $orders = xn("order");
         foreach ($fields as $index => $field) {
             $field = trim($field);
             if (!empty($field)) {
                 $attrs[$field] = $orders[$index] == "asc" ? 1 : -1;
             }
         }
         if (empty($attrs)) {
             $this->message = "Index contains one field at least.";
             $this->display();
             return;
         }
         //Options
         $options = array();
         $minBound = x("min_bound");
         if (is_numeric($minBound)) {
             $minBound = floatval($minBound);
             $options["min"] = $minBound;
         }
         $maxBound = x("max_bound");
         if (is_numeric($maxBound)) {
             $maxBound = floatval($maxBound);
             $options["max"] = $maxBound;
         }
         $bits = x("bits");
         if (is_numeric($bits)) {
             $bits = intval($bits);
             $options["bits"] = $bits;
         }
         //name
         $name = trim(xn("name"));
         if (!empty($name)) {
             $options["name"] = $name;
         }
         $collection->ensureIndex($attrs, $options);
         $this->redirect("collection.collectionIndexes", array("db" => $this->db, "collection" => $this->collection));
     }
     $this->display();
 }