title: array of promises containing cassandra queris not triggering well
body: <p>I'm currently trying to fill a cassandra table with the content of an xlsx file, but i'm facing a problem.</p>
  
  <p>I managed to do an array with all the queries necessary to fill my table ("insert into my_table (values name, ...) values (values, ...);" ).
  So my array got like 7000 strings.</p>
  
  <p>I'm then doing a promise and inside this promise I made a loop to fill and array of promises in order to trigger the first promise when all the promises are over.</p>
  
  <p>this is the code I made</p>
  
  <p>index.js =></p>
  
  <pre><code>const ImportFileContent = require("./scripts/import_file_content")
  const InsertDb = require("./scripts/insertDb")
  
  const cassandra = require('cassandra-driver');
  const databaseConfig = require('./config/database.json');
  
  const authProvider = new cassandra.auth.PlainTextAuthProvider(databaseConfig.cassandra.username, databaseConfig.cassandra.password);
  
  const db = new cassandra.Client({
      contactPoints: databaseConfig.cassandra.contactPoints,
      authProvider: authProvider
  });
  
  
  // ImportFileContent.importFileContent return an array of string, those strings contains all the 7000+ queries
  ImportFileContent.importFileContent().then(queries =&gt; {
      InsertDb.clients(db, queries).then(result =&gt; {
          console.log(result);
           db.shutdown(function (err, result) {
          });
      });
  });
  </code></pre>
  
  <p>insertDb.js => </p>
  
  <pre><code>let DB = null;
  
  module.exports = {
      ClientsLeasing: function (db, queries) {
          DB = db;
          return insertClientsLeasing(queries);
      }
  }
  
  function insertClientsLeasing(queries) {
      return new Promise((resolve, reject) =&gt; {
          let nbError = 0;
          let nbSuccess = 0;
          let promisesArray = [];
          //I made i &lt;2000 here because my cassandra setup doesn't manage more than 2048 request in parallele
          for (let i = 0; i &lt; 2000; i++) {
              promisesArray.push(new Promise(function (resolve, reject) {
                  DB.execute(queries[i], function (err, result) {
                      if (err) {
                          nbError++;
                          reject(err)
                      } else {
                          nbSuccess++;
                          resolve();
                      }
                  });
              }));
          }
          Promise.all(promisesArray).then((result) =&gt; {
              console.log("is over")
              console.log("over ===================== success =&gt; ", nbSuccess, "                    errors =&gt; ", nbError);
              resolve("success");
          }).catch((error) =&gt; {
              console.log(error);
              console.log("is over error")
              console.log("over ===================== success =&gt; ", nbSuccess, "                    errors =&gt; ", nbError);
              resolve("error");
          });
  
      });
  }
  </code></pre>
  
  <p>My table got two primary keys the creation date (wich is now()) and the client id that may be in multiple rows of the xlsx (that can be the source of the problem ?).</p>
  
  <p>So now when i launch this code my output is <a href="https://i.stack.imgur.com/C5Tuy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C5Tuy.png" alt="enter image description here"></a></p>
  
  <p>then when i do a count in the table via cqls i only get 1962 rows with this output 
  <a href="https://i.stack.imgur.com/frhEW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/frhEW.png" alt="enter image description here"></a></p>
  
  <p>I feel like i'm missing something in the way I use my promises. I don't really get it.</p>
  
  <p>Thanks</p>