пропадает коннект с базой и появляется ошибка
UnhandledPromiseRejectionWarning: MongoTimeoutError: Server selection timed out after 30000 ms
at Timeout.setTimeout [as _onTimeout] (/root/logistician_deploy_07.07.2020/node_modules/mongodb/lib/core/sdam/server_selection.js:309:9)
at ontimeout (timers.js:482:11)
at tryOnTimeout (timers.js:317:5)
at Timer.listOnTimeout (timers.js:277:5)
(node:26567) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:26567) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
КОД:
router.get('/distance', async (req,res) =>{
var url = require('url');
var url_parts = url.parse(req.url, true);
var query = url_parts.query;
const distances = await loadAllDistances();
try{
let dis = await distances.find({'fromCity':query.fromCity,'toCity':query.toCity}).toArray();
if(query.fromCity === query.toCity){
return res.send({'fromCity':query.fromCity,'toCity':query.toCity,'distation':0});
}else if(dis.length === 0){
return res.send('NOT')
}else{
return res.send(dis);
}
}catch(err){
return res.send(err)
}
});
async function loadAllDistances(){
const client = await mongodb.MongoClient.connect(
'mongodb://localhost:27017/logistician',
{
useNewUrlParser: true,
useUnifiedTopology: true
});
return client.db('logistician').collection('distance');
}