var all = db.getCollection('logging').find({"Properties.EnterpriseId":{$ne:null},"Properties.AccountId":null}).sort({"Date":-1});
all.forEach(
function(value,index,arr){
if(value.Properties.AccountId == null){
db.logging.update({'_id':ObjectId(value._id.str)},{$set:{'Properties.AccountId':value.Properties.EnterpriseId}}, false, true)
}
}
);
The above code only updates 100 pieces at a time, sometimes only updates a few hundred pieces, and 200,000 pieces of data cannot be updated completely at one time. Why is this?
There are several points that are not very clear:
It looks like a shell script, doesn’t it?
Since the conditions include
{"Properties.AccountId":null}
, whyif(value.Properties.AccountId == null)
? Or what you want to judge isAccountId === null
?
update
Details of the method can be viewedDocument. The definition in the document is:db.collection.update(query, update, options)
, so I don’t know the lastfalse
Andtrue
What was the intention?upsert
Andmulti
? In this case, it should be:db.logging.update({'_id':ObjectId(value._id.str)},{$set:{'Properties.AccountId':value.Properties.EnterpriseId}}, {upsert: false, multi: true})
But you’re using
_id
There should be no conditionsmulti
What is it? Well, it’s better to say clearly what you meant, so I won’t speculate.You are using cyclic updates, and each cycle is conditional. If you want to update 200,000 items, can these conditions cover the complete 200,000 items of data?