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 items at a time, sometimes only a few hundred items are updated, and 200,000 items of data cannot be updated at one time. Why is this?
There are a few things that I don’t quite understand:
Looks like a shell script, right?
Since there is
{"Properties.AccountId":null}
,为什么还要if(value.Properties.AccountId == null)
?或者你想判断的是AccountId === null
?update
方法的详细说明可以查看文档。文档中的定义是:db.collection.update(query, update, options)
,所以不知道最后的false
和true
本意是想查什么?upsert
和multi
?This should be:But what are you using? Well, it's better to state your original intention clearly, so I won't guess.
_id
条件应该也没有multi