Skip to content

Instantly share code, notes, and snippets.

@asaushkin
Created April 9, 2016 12:55
Show Gist options
  • Save asaushkin/7f256e5dbc499e6f1520598e66ca0d09 to your computer and use it in GitHub Desktop.
Save asaushkin/7f256e5dbc499e6f1520598e66ca0d09 to your computer and use it in GitHub Desktop.
mongodb
var mongo = require('mongodb');
var express = require('express');
var monk = require('monk');
var db = monk('localhost:27017/test');
var app = new express();
app.use(express.static(__dirname + '/public'));
app.get('/',function(req, res) {
db.driver.admin().listDatabases(function(e, dbs){
res.json(dbs);
});
});
app.get('/collections',function(req,res){
db.driver.collectionNames(function(e,names){
res.json(names);
})
});
app.get('/collections/:name',function(req,res){
var collection = db.get(req.params.name);
collection.find({},{limit:20},function(e,docs){
res.json(docs);
})
});
app.listen(3000)
{
"name": "mongoui",
"version": "0.0.1",
"engines": {
"node": ">= v0.6"
},
"dependencies": {
"mongodb":"*",
"monk": "*",
"express": "*"
}
}
docker run --name mongodb -p 27017:27017 -p 28017:28017 -d mongo --rest --httpinterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment