MongoDB Batch Modification

Source: Internet
Author: User
Tags mongodb require


Ideas:

1, concurrent multi-link

2, single link


The concurrency is not said, directly more than a few db just fine. A single link needs to use callback recursion. Mark down


var Db = require (' MongoDB ').
Db; var Server = require (' MongoDB ').
Server; var md5db = {//database config _dbconf: {dbName: ' comment ',//database name ServerIP: ' xxxxxx ',//database access Ip,fedev machine IP serverport: XXXX//mongodb Access Port}, Init:function () {}, itemindex:0, Updatefilesmodified:function (objarray,callback) {var dbCon
		f = this._dbconf;
        var = this;
        var db = new db (Dbconf.dbname, New Server (Dbconf.serverip, Dbconf.serverport), {safe:true});
			Db.open (err, db) {var list = Db.collection (' files ');
        Self.updateinstance (list, objarray,db);
	});
		}, Updateinstance:function (list,items,db) {var = this; List.update ({Fileid:items[self.itemindex]}, {$inc: {modified:1}}, {upsert:true, w:1}, function (E
				RR, 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;


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.