I'm currently working on inserting data into a MongoDB collection. I have a loop set up where I am receiving sample data in each iteration as shown below:
13:24:24:007,Peter,male,3720,yes
13:24:24:007,John,female,1520,yes
13:24:24:023,John,female,9720,yes
13:24:24:023,Mario,male,9820,no
13:24:24:023,Katy,male,4320,no
13:24:24:038,John,male,3620,no
These values correspond to the following field names:
currenttime, custname, gender, custid, ismember
I am looking for a way to efficiently insert this data into a MongoDB collection with the appropriate field names. I am unsure of how to utilize MongoDB's bulk insert feature for this task.
One approach I've considered is storing this data in an array variable (split by new line), then further splitting each item within the array (split by comma) to create a loop that generates objects to be inserted into the MongoDB collection. However, I find this method to be quite simplistic and slow. I am confident that there is a more effective way to achieve this. Any suggestions would be greatly appreciated.