Permalink
Browse files

Merge branch 'release/v0.3.4'

  • Loading branch information...
2 parents 4c83917 + 8a898f9 commit b0f0be47d4ffed110c6ed2dfab117bd8a3e5a5cf @andzdroid andzdroid committed May 3, 2012
Showing with 60 additions and 18 deletions.
  1. +2 −2 README.md
  2. +26 −10 app.js
  3. +5 −1 config.js
  4. +5 −3 package.json
  5. +1 −0 test/mocha.opts
  6. +13 −0 test/utils.js
  7. +8 −2 utils.js
View
@@ -4,6 +4,6 @@ mongo-express
Web-based MongoDB admin written with Node.js and express
-Master (stable) branch build status: [![Build Status](https://secure.travis-ci.org/andzdroid/mongo-express.png?branch=master)](http://travis-ci.org/andzdroid/mongo-express)
+[![Build Status](https://secure.travis-ci.org/andzdroid/mongo-express.png?branch=master)](http://travis-ci.org/andzdroid/mongo-express) - Master (stable) branch
-Develop branch build status: [![Build Status](https://secure.travis-ci.org/andzdroid/mongo-express.png?branch=develop)](http://travis-ci.org/andzdroid/mongo-express)
+[![Build Status](https://secure.travis-ci.org/andzdroid/mongo-express.png?branch=develop)](http://travis-ci.org/andzdroid/mongo-express) - Develop branch
View
36 app.js
@@ -76,15 +76,16 @@ var mainConn; //main db connection
//Update the collections list
-var updateCollections = function(db, db_name, callback) {
+var updateCollections = function(db, dbName, callback) {
db.collectionNames(function (err, result) {
var names = [];
for (var r in result) {
- names.push(utils.parseCollectionName(result[r].name));
+ var coll = utils.parseCollectionName(result[r].name);
+ names.push(coll.name);
}
- collections[db_name] = names.sort();
+ collections[dbName] = names.sort();
if (callback) {
callback(err);
@@ -101,17 +102,28 @@ var updateDatabases = function(admin) {
}
for (var key in dbs.databases) {
- var db_name = dbs.databases[key]['name'];
+ var dbName = dbs.databases[key]['name'];
//'local' is special database, ignore it
- if (db_name == 'local') {
+ if (dbName == 'local') {
continue;
}
- connections[db_name] = mainConn.db(db_name);
- databases.push(db_name);
+ if (config.mongodb.whitelist.length != 0) {
+ if (!_.include(config.mongodb.whitelist, dbName)) {
+ continue;
+ }
+ }
+ if (config.mongodb.blacklist.length != 0) {
+ if (_.include(config.mongodb.blacklist, dbName)) {
+ continue;
+ }
+ }
+
+ connections[dbName] = mainConn.db(dbName);
+ databases.push(dbName);
- updateCollections(connections[db_name], db_name);
+ updateCollections(connections[dbName], dbName);
}
//Sort database names
@@ -224,6 +236,10 @@ app.get('/db/:database/:collection', middleware, routes.viewCollection);
app.del('/db/:database/:collection', middleware, routes.deleteCollection);
-app.listen(config.site.port || 80);
+if (!module.parent) {
+ app.listen(config.site.port || 80);
-console.log("Mongo Express server listening on port " + (config.site.port || 80));
+ console.log("Mongo Express server listening on port " + (config.site.port || 80));
+} else {
+ module.exports = app;
+}
View
@@ -8,7 +8,11 @@ module.exports = {
password: '',
autoReconnect: true,
//poolSize: size of connection pool
- poolSize: 4
+ poolSize: 4,
+ //whitelist: hide all databases except the ones in this list (empty list for no whitelist)
+ whitelist: [],
+ //blacklist: hide databases listed in the blacklist (empty list for no blacklist)
+ blacklist: []
},
site: {
//baseUrl: the URL that mongo express will be located at
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.3.3",
+ "version": "0.3.4",
"repository": {
"type": "git",
"url": "git://github.com/andzdroid/mongo-express.git"
@@ -21,6 +21,8 @@
"engine": "node >= 0.6",
"license": "MIT",
"scripts": {
- "start": "node app"
- }
+ "start": "node app",
+ "test": "./node_modules/.bin/mocha"
+ },
+ "main": "./app"
}
View
@@ -0,0 +1 @@
+--reporter dot
View
@@ -0,0 +1,13 @@
+var utils = require('../utils.js');
+var expect = require('chai').expect;
+
+describe('Utils', function() {
+ describe('parseCollectionName', function() {
+ it('should return the collection and database of a full collection namespace', function() {
+ var result = utils.parseCollectionName('databaseName.collection.x.y');
+
+ expect(result).to.have.property('name', 'collection.x.y').to.be.a('string');
+ expect(result).to.have.property('database', 'databaseName').to.be.a('string');
+ });
+ });
+});
View
@@ -1,5 +1,11 @@
+//Given a full collection namescpace, returns the database and collection
exports.parseCollectionName = function parseCollectionName(full_name) {
var coll_parts = full_name.split('.');
- coll_parts.splice(0,1);
- return coll_parts.join('.');
+
+ if (coll_parts.length <= 1) {
+ console.error('Cannot parse collection name!');
+ }
+
+ var database = coll_parts.splice(0,1);
+ return { name: coll_parts.join('.'), database: database.toString() };
};

0 comments on commit b0f0be4

Please sign in to comment.