Directly on the code
' Use strict 'varFs=require (' FS '),Mongodb=require (' MongoDB '). Mongoclient, Assert=require (' Assert '), URL= ' Mongodb://username:[email protected]:27017/dbname?authmechanism=mongodb-cr&authsource=admin '; mongodb.connect (URL,function(err,db) {assert.equal (err,NULL); varSchool=db.collection (' School '); Fs.readfile (' School.txt ',function(err,data) {var_data=data.tostring (). Split ('; ')); for(vari=0;i<_data.length-1;i++){ var_item=_data[i]; var_arr=_item.split (', '); var_json={' code ': _arr[0], ' type ': _arr[1], ' province ': _arr[2], ' title ': _arr[3], ' isActive ':false}; School.insert (_json,function(Err,result) {console.log (result); }) } })})
Save As JS file execute node xx.js wait < 500ms
Done! --------Note the path to the file and the configuration of your database parameters
Additional Documents Http://files.cnblogs.com/files/zboy/school.txt.tar.gz
National University list file (newer) + Nodejs import MongoDB Database