You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect await mongoose.connect(...) to perform this check. Either it could throw an exception or close the existing connection then reopen it again.
The text was updated successfully, but these errors were encountered:
Using the current versions of Mongoose and TypeScript @types/express.
Opening a connection fails to return the Promise if the connection is already open.
Here is the my function:
async MongodbConnection(dbname: string): Promise
{
try
{
await mongoose.connect(
mongodb://mongodb:27017/${dbname}?authSource=admin
, {'useNewUrlParser': true,
'useUnifiedTopology': true,
'useFindAndModify': false,
'useCreateIndex': true,
'user': 'docker',
'pass': 'password'
});
}
catch(error)
{
throw error;
}
return mongoose.connection;
}
To fix this either close the connection before calling this function again or add a check to this function to ensure the connection is not open.
if(mongoose.connection.readyState !== 1)
{
await mongoose.connect(
mongodb://webservice:27017/${dbname}?authSource=admin
, {'useNewUrlParser': true,
'useUnifiedTopology': true,
'useFindAndModify': false,
'useCreateIndex': true,
'user': 'docker',
'pass': 'password'
});
}
I would expect await mongoose.connect(...) to perform this check. Either it could throw an exception or close the existing connection then reopen it again.
The text was updated successfully, but these errors were encountered: