Use
data$ MONGO Localhost:27017/jd_51job_raw updatename.js--shell
JS Script: Updatename.js
var cursor =db.getcollectionnames (); for(i=0;i<cursor.length;i++){ if("system.indexes"==cursor[i]| |"System.profile"==Cursor[i]) { Print("Find System"); Continue; } Else{Curcol=db.getcollection (Cursor[i]); Print("Now processing ...", Curcol); Print(Curcol.count ()); Curcol.find (). ForEach (function (item) {curcol.update ({"_id": item._id},{"$set":{"Jdjob.jobdiploma": Item.jobdiploma}});Curcol.update ({"_id": item._id},{"$unset":{"Jobdiploma": 0}}); }); Printjson (Curcol.findone ()); } }
updatename.py
#!/usr/bin/env python#Coding=utf-8 fromPymongoImportmongoclient fromBson.json_utilImportdumps fromMultiprocessingImportpoolclient= Mongoclient ("mongodb://localhost:xxxxx/") DB=Client.jd_51job_rawcols= Db.collection_names (include_system_collections=False) cols=Sorted (cols)defDel_jobdiploma (colname):Print "=="*20, ColName Col=db.get_collection (colname)
Col.update ({},{"$unset":{"Jobdiploma":""}},multi=True)PrintDumps (Col.find_one (), ensure_ascii=false,indent=4) Print ""
# 10 processes come together!
Pools= Pool (10) Pools.map (del_jobdiploma,cols)
MongoDB JS script or Pymongodb script modifies the field values of the database