Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'release/v0.6.0'

  • Loading branch information...
commit e11b7fd178124bb8dac96c207f6fb50d5ac88342 2 parents ee875da + 1d0c91d
@andzdroid authored
View
1  app.js
@@ -233,6 +233,7 @@ var middleware = function(req, res, next) {
app.get('/', middleware, routes.index);
app.get('/db/:database/:collection', middleware, routes.viewCollection);
app.del('/db/:database/:collection', middleware, routes.deleteCollection);
+app.put('/db/:database/:collection', middleware, routes.renameCollection);
app.get('/db/:database', middleware, routes.viewDatabase);
app.post('/db/:database', middleware, routes.addCollection);
View
2  package.json
@@ -2,7 +2,7 @@
"author": "Chun-hao Hu <hu.chunhao@gmail.com> (http://blog.huchunhao.com)",
"name": "mongo-express",
"description": "Web-based admin interface for MongoDB",
- "version": "0.5.0",
+ "version": "0.6.0",
"repository": {
"type": "git",
"url": "git://github.com/andzdroid/mongo-express.git"
View
27 routes/collection.js
@@ -69,3 +69,30 @@ exports.deleteCollection = function(req, res, next) {
});
});
};
+
+
+exports.renameCollection = function(req, res, next) {
+ var name = req.body.collection;
+
+ if (name == undefined) {
+ //TODO: handle error
+ return res.redirect('back');
+ }
+
+ //Collection names must begin with a letter or underscore, and can contain only letters, underscores, numbers or dots
+ if (!name.match(/^[a-zA-Z_][a-zA-Z0-9\._]*$/)) {
+ //TODO: handle error
+ return res.redirect('back');
+ }
+
+ req.collection.rename(name, function(err, collection) {
+ if (err) {
+ //TODO: handle error
+ console.error(err);
+ }
+
+ req.updateCollections(req.db, req.dbName, function() {
+ res.redirect('/db/' + req.dbName + '/' + name);
+ });
+ });
+};
View
1  routes/index.js
@@ -5,6 +5,7 @@ exports.viewDatabase = db.viewDatabase;
exports.viewCollection = coll.viewCollection;
exports.addCollection = coll.addCollection;
exports.deleteCollection = coll.deleteCollection;
+exports.renameCollection = coll.renameCollection;
//Homepage route
View
23 views/collection.html
@@ -36,16 +36,37 @@
{% endif %}
#}
+<div class="row">
+<div class="span5">
+
+<h2>Rename Collection</h2>
+<form method="POST" action="db/{{ dbName }}/{{ collectionName }}" class="well form-inline">
+ <input type="hidden" name="_method" value="put">
+ <div class="input-prepend">
+ <span class="add-on">{{ dbName }} . </span>
+ <input class="input-medium" type="text" id="collection" name="collection" placeholder="{{ collectionName }}">
+ </div>
+ <button type="submit" class="btn btn-primary">
+ <i class="icon-folder-open icon-white"></i>
+ Rename
+ </button>
+</form>
+
+</div>
+<div class="span4">
+
<h2>Delete Collection</h2>
<form method="POST" action="db/{{ dbName }}/{{ collectionName }}" class="well">
<input type="hidden" name="_method" value="delete">
<p>Are you sure you want to delete this collection? All documents will be deleted.</p>
- <button type="submit" class="btn btn-danger btn-large">
+ <button type="submit" class="btn btn-danger">
<i class="icon-trash icon-white"></i>
Delete
</button>
</form>
+</div>
+
{% endblock %}
View
2  views/database.html
@@ -7,7 +7,7 @@
<form class="well form-inline" method="POST">
<div class="input-prepend">
<span class="add-on">{{ dbName }} . </span>
- <input class="span3" type="text" id="collection" name="collection" placeholder="Collection Name">
+ <input class="input-medium" type="text" id="collection" name="collection" placeholder="Collection Name">
</div>
<button type="submit" class="btn btn-primary">
<i class="icon-folder-open icon-white"></i>

0 comments on commit e11b7fd

Please sign in to comment.
Something went wrong with that request. Please try again.