I am trying write a program to parse and insert iis logs data in to mongodb. The files aren\'t that huge it\'s around 600 lines. Trying to convince my management nodejs and
I'm 100% sure but as far as I can see you are inserting data synchronous. I mean once you get a line you try to insert it and don't wait for the result. Try using another approach:
Something like that:
var lines = [];
var readAllLines = function(callback) {
// store every line inside lines array
// and call the callback at the end
callback();
}
var storeInDb = function(callback) {
if(lines.length === 0) {
callback();
return;
}
var line = lines.shift();
collection.insert(line, function (err, docs) {
storeInDb(callback);
});
}
mongoClient.open(function (err, mongoClient) {
console.log(err);
if (mongoClient) {
readAllLines(function() {
storeInDb(function() {
// lines are inserted
// close the db connection
})
});
}
});