Just a bit of background, MongoDB does not crash if I use insertMany
instead.
So here's the relevant code:
var propertiesObject = { results: 5000 };
request({url: "https://randomuser.me/api", qs:propertiesObject}, function(err, r, body) {
if(err) { console.log(err); return; }
console.log("Get response: " + r.statusCode);
let j = JSON.parse(r.body)
let id = 1
let users = j.results
for (let user of users)
{
MongoClient.connect("mongodb://localhost:27017/test", function (err, db) {
db.collection('Persons', function (err, collection) {
collection.insert({ id, first_name: user.name.first, lastName: user.name.last })
})
})
id++
}
});
This causes MongoDB to crash, which requires me to run a restart of it. Is there any particular reason why it would do that? It won't crash if it's a smaller value e.g. 10