思路:
1,並發多連結
2,單連結
並發就不說了,直接多new幾個db就好了。單連結需要使用回調遞迴。Mark 下
var Db = require('mongodb').Db;var Server = require('mongodb').Server;var MD5DB = {//資料庫配置_dbConf: {dbName: 'comment', //資料庫名稱serverIp: 'xxxxxx', //資料庫訪問ip,fedev機器ipserverPort: xxxx //mongodb訪問連接埠},init: function(){},itemIndex:0,updateFilesModified:function(objArray,callback){var dbConf = this._dbConf;var self = this; var db = new Db(dbConf.dbName, new Server(dbConf.serverIp, dbConf.serverPort), {safe: true}); db.open(function(err, db) { var list = db.collection('files');self.updateInstance(list, objArray,db); });},updateInstance:function(list,items,db){var self = this;list.update({fileId: items[self.itemIndex]}, {$inc : {modified: 1 }}, {upsert:true,w: 1}, function(err, item) {if(err) console.log(err.stack);self.itemIndex++;if( self.itemIndex >= items.length){db.close();self.itemIndex =0;}else{self.updateInstance(list,items,db)}});}};module.exports = MD5DB;