MongoError: server instance pool was destroyed
I found the issue...
I forgot the fact that javaScript is Async :) the mongo.close() was the issue. I commented it and it worked
I think db.closeConnection()
is called before all request responses are handled, and database access is finished.
The cause for this behaviour may be, that you are only waiting for creating the requests, but you are not waiting for their result (response).
You start the request with a statement like this inside an async function:
request(url, (function(country) {
...
})(...));
That means, the async function will wait for the request(...)
function call, but not for the callback function which handles the response.
You can also use request(...)
in the following way:
const response = await request(url);
Now your async function will wait for the response.