bulk更新mongodb的脚本
/** * 批量更新数据库对象* 1. 按条件批量更新
* 2. 无条件批量更新
*/
/** 1. 按条件批量更新 **/
// step 1: get key-value
var>
var valueArray = [];
var>
db.conch_ChargeSchedule.find({'predictChargeValue':{$exists:false}}).forEach(function(obj){
idx++;
idArray=obj._id;
valueArray=obj.planValue;
});
// step 2: update
var bulk = db.conch_ChargeSchedule.initializeUnorderedBulkOp();
for(var i=0; i<idArray.length; i++){
bulk.find( { _id:>
}
bulk.execute();
/** 2. 无条件批量更新 **/
var bulk = db.conch_ChargeSchedule.initializeUnorderedBulkOp();
bulk.find({}).update({ $set: { isPlanValueUpdatable: true, isStatusUpdatable:true, isStartDateUpdatable:true } });
bulk.execute();
页:
[1]