首页 > 代码库 > mongo批量更新
mongo批量更新
update的如果要批量更新是无能为力的,如果有多条匹配的结果,但结果是只能更新一条。
用bulk来进行处理
var bulk = db.HIS_ALARM.initializeUnorderedBulkOp();
bulk.find( {"ID_factory": 2,"ID_alarm_type": 1,"ID_event_type": 5,"Ack_statue" : {"$nin" : [1]}} ).update( { $set: { "Ack_statue" : 1 ,"Ack_time" : 211020472 ,"ID_ack_user" : 5} } );
bulk.find( {"ID_factory": 2,"ID_alarm_type": 1,"ID_event_type": 6,"Ack_statue" : {"$nin" : [1]}} ).update( { $set: { "Ack_statue" : 1 ,"Ack_time" : 211020472 ,"ID_ack_user" : 5} } );
bulk.find( {"ID_factory": 2,"ID_alarm_type": 2,"ID_event_type": 5,"Ack_statue" : {"$nin" : [1]}} ).update( { $set: { "Ack_statue" : 1 ,"Ack_time" : 211020472 ,"ID_ack_user" : 5} } );
bulk.find( {"ID_factory": 2,"ID_alarm_type": 2,"ID_event_type": 9,"Ack_statue" : {"$nin" : [1]}} ).update( { $set: { "Ack_statue" : 1 ,"Ack_time" : 211020472 ,"ID_ack_user" : 5} } );
bulk.find( {"ID_factory": 2,"ID_alarm_type": 2,"ID_event_type": 10,"Ack_statue" : {"$nin" : [1]}} ).update( { $set: { "Ack_statue" : 1 ,"Ack_time" : 211020472 ,"ID_ack_user" : 5} } );
bulk.find( {"ID_factory": 2,"ID_alarm_type": 2,"ID_event_type": 11,"Ack_statue" : {"$nin" : [1]}} ).update( { $set: { "Ack_statue" : 1 ,"Ack_time" : 211020472 ,"ID_ack_user" : 5} } );
bulk.find( {"ID_factory": 2,"ID_alarm_type": 2,"ID_event_type": 12,"Ack_statue" : {"$nin" : [1]}} ).update( { $set: { "Ack_statue" : 1 ,"Ack_time" : 211020472 ,"ID_ack_user" : 5} } );
bulk.find( {"ID_factory": 2,"ID_alarm_type": 2,"ID_event_type": 13,"Ack_statue" : {"$nin" : [1]}} ).update( { $set: { "Ack_statue" : 1 ,"Ack_time" : 211020472 ,"ID_ack_user" : 5} } );
bulk.execute();
mongo批量更新