Skip to content

Instantly share code, notes, and snippets.

@yefim
Created April 9, 2014 23:51
Show Gist options
  • Select an option

  • Save yefim/10331129 to your computer and use it in GitHub Desktop.

Select an option

Save yefim/10331129 to your computer and use it in GitHub Desktop.
Mongodb native driver and Expressjs intergration
var express = require('express');
var app = express();
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
var collection = db.collection('collection');
app.get('/', function(req, res) {
collection.find().toArray(function(err, results) {
res.json(results);
});
});
app.get('/insert', function(req, res) {
collection.insert({a: 1}, function() {
res.redirect('/');
});
});
app.listen(3000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment