Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var sys = require('sys'),
- http = require('http'),
- mongodb = require('mongodb');
- http.createServer(function(req, res) {
- var server = new mongodb.Server("127.0.0.1", 27017, {});
- var db = new mongodb.Db('mongo', server, {});
- db.open(function (error, client) {
- if (error) {
- db.close();
- throw error;
- }
- var collection = new mongodb.Collection(client, 'basic');
- collection.find({'_id':String(Math.floor(Math.random()*100000))}, {}, function(err, cursor) {
- if(err == null){
- cursor.toArray(function(err, docs){
- db.close();
- res.writeHead(200, {'Content-Type': 'text/html'});
- res.write('Goood');
- res.end();
- });
- }else{
- db.close();
- res.writeHead(200, {'Content-Type': 'text/html'});
- res.write('Bad');
- res.end();
- throw err;
- }
- });
- });
- }).listen(8080);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement