title: How can I convert string to int of array in MongoDB?
body: <p>Here is the dataset</p>
  
  <pre><code>// Data 1
  { name : 111, 
    factors : [
      {name:"f1", value:"dog", unit : "kg"},
      {name:"f2", value:"0"}
    ]
  },// data2
  { name : 112, 
    factors : 
    [
      {name:"f1", value:"cat", unit : "g"},
      {name:"f2", value:"13"}
    ]
  }
  // 100,000 more data ...
  </code></pre>
  
  <p>I would like to convert the value of factor <code>f2</code> to be <code>number</code>.</p>
  
  <pre><code>db.getCollection('cases').find({ 
          factors : {
              $elemMatch : {
                   name : "f2",
                   value  : {$type : 2}
              }
          }
  }).forEach(function(doc, i){
          doc.factors.forEach(function(factor){
              if(factor.name == "f2"){
                 factor.value = !isNaN(factor.value) ? parseInt(factor.value) : factor.value;
              }
          });
          db.cases.save(factor);
  });
  </code></pre>
  
  <p>However, it can only update about <strong>75~77</strong> data for each execution. I am not sure why and I guess the problem is that the <code>save()</code> is async, so we can not initiate too many <code>save()</code> at the same time.</p>
  
  <p>What should I do?</p>