var mongo = require(‘mongodb’); var host = 'localhost’; //var port = mongo.Connection.DEFAULT_PORT; 这一行。。。。 var server = new mongo.Server(host, 3421, {auto_reconnect:true}); var db = new mongo.Db('node-mongo-examoles’,server,{safe:true});
db.open(function (err, db) { if(err) throw err; else { console.log(‘success’); db.close(); } });
db.on('close’,function (err,db) { // body… if(err) throw err; else { console.log(‘success close’); } });