Why insert/put within loop insert only 1 row?

I have been trying to put data of about 100 rows in foreach loop in node js…

Unfortunately I didn’t find any solution… It just insert 1 row and, print error message: AerospikeError: Client timeout: iterations=1 lastNode=localhost:3000

There must be some problem here because it just insert 1 row… I couldn’t find solution for this simple problem…

Here is my node js code:: array values gets from mongo db;

const allEvents = await Event.find();
        const key = new Aerospike.Key('evDb', 'allEvents', 'PK');
        for(var i=0; i < allEvents.length; i++){
            await client.put(key, {
                PK: allEvents[i]._id.toString(),    
                eventContent: {...allEvents[i]},
            });
            if(error){
                console.log(error);
            }
        }

Remember, it insert 1 row, so data is correct as per I have checked…

It’s very difficult for beginners as they don’t have enough demonstration of such…

Your suggestions will help me save several hours of unfruitful work hours

thank you

I don’t know much about the Node.js client but the error indicates the transaction timed out. Did you try (just to troubleshoot) writing two records individually… could it be the problem is in the way elements are consumed from ‘allEvents’ and fed into the Aerospike client?

Oh, I checked with a colleague of mine who mentioned that the key is a constant, so that would explain the single record if all the updates are done under the same key (you probably would ant to update the key with the event’s ID on every iteration). Not sure what the timeout error is or where it comes from but it is also not clear from the code where this error variable is getting set. Hope this helps.