I am trying to insert multiple values into the nosql database cassandra, using an array, but when I use the code below, instead of adding a row for each of the values stored in foo5 it only ends up adding two rows. The two rows added contain the same value in col5 and col3

var insert2 = "INSERT INTO content (col, col2, col3, col4, col5) VALUES (?, ?, ?, ?, ?);" for(var i = 0; i < foo5.length; i++) { client.execute(insert2, [foo, foo2, foo3, foo4, foo5[i]], {prepare : true}, function(err, result) { if(err) throw err; }); }

for example this is what the result looks like( col is the primary key):

col | col2 | col3 | col4 | col5 ---------+---------+-----------+--------+-------- 8909265 | text | 8759 | 5332 | 7480 1769288 | text | 8759 | 5332 | 7480

I want to add a row for every single value in the array foo5 . This is the expected result. How can I achieve this:

col | col2 | col3 | col4 | col5 ---------+---------+-----------+--------+-------- 8909265 | text | 8759 | 5332 | 1234 1769288 | text | 8759 | 5332 | 5678 3254786 | text | 8759 | 5332 | 9101112 4357234 | text | 8759 | 5332 | 1314151617

assuming foo5 = {1234, 5678, 9101112, 1314151617};

UPDATE:

after adding a recursive function as suggested by someRandomSerbianGuy this is what my code looks like:

function recursion(i, counter) { var insert2 = "INSERT INTO content (col, col2, col3, col4, col5) VALUES (?, ?, ?, ?, ?);" if(counter == i) { return; } else { client.execute(insert2, [foo, foo2, foo3, foo4, foo5[i]], {prepare : true}, function(err, result) { if(err) throw err; recursion(++i, counter); }); } } recursion(0, foo5.length);

I am still getting the same results.