title: Promise.all concurrency
body: <p>I'm developing an Electron app with NeDB storage (a javascript document oriented DB that uses Mongodb-like API), this code is not Electron-related though.</p>
  
  <p>I'm trying to update <code>extractions</code> field of all documents. This code is simplified, the real code doesn't add just <code>[1, 2, 3]</code>.
  The problem is this code add a second document with the same <code>_id</code> for each document in the db, so it's like bypasses the unique <code>_id</code> constraint.
  You can run this code and see multiple <code>_id</code> with the same value.</p>
  
  <p><strong>EDIT:</strong> <strong>to better see the problem</strong>, please execute the PART 1 first, then comment it and execute the PART 2. You will see 2 documents with the same _id. One with  <code>extractions: [1, 2, 3]</code> and one with  <code>extractions: ["test1", "test2","test3"]</code> .</p>
  
  <pre><code>const Datastore = require('nedb');
  let db = new Datastore({filename: "data2.db", autoload: true});
  
  
  //---------PART 1------------
  db.insert({_id: new Date('03/06/2017Z'), extractions: [1, 2, 3]}, function (err, newDoc) {
      if (err)
          console.log(err);
      else
          console.log(newDoc);
  });
  
  
  
  //---------PART 2------------    
  /* db.find({})
      .sort({_id: -1})
      .exec(function (err, docs) {
          var promiseList = [];
          docs.forEach(function (doc) {
              promiseList.push(PromisifiedFindAndUpdate(doc._id))
          });
          Promise.all(promiseList).then(values =&gt; {
              console.log(values)
          });
      });
    */
  
   let PromisifiedFindAndUpdate = function (id) {
          return new Promise(function (resolve, reject) {
              db.findOne({_id: id}, function (err, doc) {
                  let updated_extractions = ["test1", "test2","test3"];
                  db.update({_id: id}, {$set: {"extractions": updated_extractions}}, {}, function (err, docs) {
                      if (err) {
                          return reject(err);
                      }
                      return resolve(docs);
                  });
              });
  
          });
      };
  </code></pre>