Skip to content

Instantly share code, notes, and snippets.

@eyadof
Created October 5, 2012 20:03
Show Gist options
  • Save eyadof/3842034 to your computer and use it in GitHub Desktop.
Save eyadof/3842034 to your computer and use it in GitHub Desktop.
MongoDB Node.js Driver
var DB = require('mongodb').Db;
var Server = require('mongodb').Server;
var x = "" ;
new DB('simple_tutorial',new Server('127.0.0.1',27017)).open(
function(err,db){
db.collection('documents',function(err,collection){
collection.insert({age:21,name:'eyad'},function(err,doc){
collection.findOne({age:21},function(err,resaults){
console.log('age is :' + resaults.age);
x = resaults.age;
db.close();
});
});
});
});
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<em>'+x+'</em>');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment