Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'release/v0.15.0'

  • Loading branch information...
commit 89458ee8237cdfcf4ff500b3e3dddf3df889433d 2 parents 1c5d6e5 + 90b3dc4
@andzdroid authored
View
7 HISTORY.md
@@ -1,7 +1,12 @@
+0.15.0
+------
+
+* Added support for BSON data types when adding/editing docs
+
0.14.1
------
-* Forgot to updated HISTORY file
+* Forgot to update HISTORY file
0.14.0
------
View
26 README.md
@@ -14,6 +14,7 @@ Current features:
* Database blacklist/whitelist
* View/add/rename/delete collections
* View/add/update/delete documents
+* Supports BSON data types
Planned features:
@@ -26,8 +27,9 @@ Planned features:
Limitations
-----------
-* Requires documents to have a document._id property
-* Cannot edit document._id property
+* Can only edit documents which have a document._id property
+* Cannot edit document._id property (will be fixed soon)
+* Converts all documents from BSON to JSON when viewing (will be fixed soon)
Screenshots
@@ -67,6 +69,26 @@ Fill in your MongoDB connection details, and any other options you want to chang
Visit `http://localhost:8081` or whatever URL/port you entered into your config.
+BSON Data Types
+---------------
+
+When adding/editing documents, you may want to use BSON data types.
+
+Here is an example of how to use them:
+
+ {
+ _id: ObjectID(), // or ObjectId()
+ long: Long(3000), // or NumberLong()
+ double: Double(4.4), // or NumberDouble()
+ ts: Timestamp()
+ }
+
+Writing this in the document editor will automatically convert the document to the BSON format.
+
+See [https://github.com/mongodb/node-mongodb-native](https://github.com/mongodb/node-mongodb-native) for a full list of supported data types.
+
+At the moment, viewing documents do not show the BSON types, they are only used when adding/editing documents.
+
License
-------
MIT License
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.14.1",
+ "version": "0.15.0",
"repository": {
"type": "git",
"url": "git://github.com/andzdroid/mongo-express.git"
View
19 routes/document.js
@@ -1,5 +1,7 @@
var config = require('../config');
-var mongodb = require('mongodb');
+var utils = require('../utils');
+var vm = require('vm');
+
exports.viewDocument = function(req, res, next) {
var ctx = {
@@ -20,13 +22,19 @@ exports.addDocument = function(req, res, next) {
}
var docJSON;
+ var sandbox = utils.getSandbox();
+
+ //JSON.parse doesn't support BSON data types
+ //Document is evaluated in a vm in order to support BSON data types
+ //Sandbox contains BSON data type functions from node-mongodb-native
try {
- docJSON = JSON.parse(doc);
+ vm.runInNewContext('doc = eval((' + doc + '));', sandbox);
} catch (err) {
req.session.error = "That document is not valid!";
- console.error(err)
+ console.error(err);
return res.redirect('back');
}
+ var docJSON = sandbox.doc;
req.collection.insert(docJSON, {safe: true}, function(err, result) {
if (err) {
@@ -49,14 +57,15 @@ exports.updateDocument = function(req, res, next) {
return res.redirect('back');
}
- var docJSON;
+ var sandbox = utils.getSandbox();
try {
- docJSON = JSON.parse(doc);
+ vm.runInNewContext('doc = eval((' + doc + '));', sandbox);
} catch (err) {
req.session.error = "That document is not valid!";
console.error(err);
return res.redirect('back');
}
+ var docJSON = sandbox.doc;
docJSON._id = req.document._id;
View
23 utils.js
@@ -1,3 +1,5 @@
+var mongodb = require('mongodb');
+
//Given a full collection namescpace, returns the database and collection
exports.parseCollectionName = function parseCollectionName(full_name) {
var coll_parts = full_name.split('.');
@@ -9,3 +11,24 @@ exports.parseCollectionName = function parseCollectionName(full_name) {
var database = coll_parts.splice(0,1);
return { name: coll_parts.join('.'), database: database.toString() };
};
+
+//Create sandbox with BSON data types
+exports.getSandbox = function() {
+ return {
+ Long: mongodb.Long,
+ NumberLong: mongodb.Long,
+ Double: mongodb.Double,
+ NumberDouble: mongodb.Double,
+ ObjectId: mongodb.ObjectID,
+ ObjectID: mongodb.ObjectID,
+ Timestamp: mongodb.Timestamp,
+ DBRef: mongodb.DBRef,
+ Binary: mongodb.Binary,
+ BinData: mongodb.Binary,
+ Code: mongodb.Code,
+ Symbol: mongodb.Symbol,
+ MinKey: mongodb.MinKey,
+ MaxKey: mongodb.MaxKey,
+ ISODate: Date
+ };
+};
View
17 views/document.html
@@ -45,7 +45,7 @@
<form method="POST" action="db/{{ dbName }}/{{ collectionName }}/{{ document._id }}">
<input type="hidden" name="_method" value="put">
- <button type="submit" class="btn btn-success btn-large">
+ <button type="submit" class="btn btn-success btn-large"{# onclick="return checkJSON()"#}>
<i class="icon-pencil icon-white"></i>
Save
</button>
@@ -63,6 +63,21 @@
matchBrackets: true,
theme: "{{ editorTheme }}"
});
+
+{# This can check for valid JSON on the client side
+ # Not used at the moment, since it doesn't allow BSON types
+ function checkJSON() {
+ var d = doc.getValue();
+
+ try {
+ docJSON = JSON.parse(d);
+ return true;
+ } catch (err) {
+ alert('This is not a valid document!');
+ return false;
+ }
+ }
+#}
</script>
{% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.