The problem of uncertain number of execution items in mongodb
为情所困
为情所困 2017-05-17 10:01:33
0
1
797
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?

为情所困
为情所困

reply all(1)
左手右手慢动作

There are a few things that I don’t quite understand:

  1. Looks like a shell script, right?

  2. Since there is {"Properties.AccountId":null},为什么还要if(value.Properties.AccountId == null)?或者你想判断的是AccountId === null?

  3. in the conditions
  4. update方法的详细说明可以查看文档。文档中的定义是:db.collection.update(query, update, options),所以不知道最后的falsetrue本意是想查什么?upsertmulti?This should be:

    db.logging.update({'_id':ObjectId(value._id.str)},{$set:{'Properties.AccountId':value.Properties.EnterpriseId}}, {upsert: false, multi: true})

    But what are you using? Well, it's better to state your original intention clearly, so I won't guess. _id条件应该也没有multi

  5. You are using a loop update, and each loop has conditions. If you want to update 200,000 pieces of data, can these conditions cover the complete 200,000 pieces of data?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template