Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release/v0.5.0'

  • Loading branch information...
commit ee875da610b550a14d2de64ff8cb87600d79b6b8 2 parents c8cbafd + fdbb847
andzdroid authored
2  app.js
View
@@ -231,10 +231,10 @@ var middleware = function(req, res, next) {
//Routes
app.get('/', middleware, routes.index);
-//app.post('/db/:database', middleware, routes.createCollection);
app.get('/db/:database/:collection', middleware, routes.viewCollection);
app.del('/db/:database/:collection', middleware, routes.deleteCollection);
app.get('/db/:database', middleware, routes.viewDatabase);
+app.post('/db/:database', middleware, routes.addCollection);
app.listen(config.site.port || 80);
2  package.json
View
@@ -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.4.0",
+ "version": "0.5.0",
"repository": {
"type": "git",
"url": "git://github.com/andzdroid/mongo-express.git"
24 routes/collection.js
View
@@ -23,6 +23,30 @@ exports.viewCollection = function(req, res, next) {
exports.addCollection = 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.db.createCollection(name, function(err, collection) {
+ if (err) {
+ //TODO: handle error
+ console.error(err);
+ }
+
+ req.updateCollections(req.db, req.dbName, function() {
+ //TODO: use session flash to show success or error message
+ res.redirect('/db/' + req.dbName + '/' + name);
+ });
+ });
};
28 routes/index.js
View
@@ -22,31 +22,3 @@ exports.index = function(req, res) {
res.render('index', ctx);
});
};
-
-//Handle form submission when creating new collection
-//TODO: Move this handler to /db/ URL when implementing REST api, to handle PUT requests
-exports.createCollection = function(req, res) {
- var db = req.db;
- var name = req.body.collectionName;
-
- 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');
- }
-
- db.createCollection(name, function(err, collection) {
- if (err) {
- //TODO: handle error
- console.error(err);
- }
-
- //TODO: use session flash to show success or error message
- res.redirect('/db/' + req.database + '.' + name);
- });
-};
2  views/database.html
View
@@ -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="collectionName" name="collectionName" placeholder="Collection Name">
+ <input class="span3" 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>
Please sign in to comment.
Something went wrong with that request. Please try again.