Created
April 9, 2014 23:51
-
-
Save yefim/10331129 to your computer and use it in GitHub Desktop.
Mongodb native driver and Expressjs intergration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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