I am using mongoose to connect to my Mongodb Atlas cluster through my nodejs server.
There is a certain operation which is done as a transaction. Mongoose needs mongoose.startSession() to be called to start a transaction. Very infrequently, this mongoose.startSession() call hangs indefinitely. There is no certain way to reproduce this.
log.info('starting lock session');
const mongoSession = await mongoose.startSession();
log.info('lock session started');
In above code, starting lock session. gets logged, but lock session started doesn't get logged when issue occurs.
I connect to the db like below:
const dburl = 'mongodb+srv://myuser:mypassword@myapp.mongodb.net/mydb?retryWrites=true&w=majority';
mongoose.connect(dburl, {useNewUrlParser: true}, err => {
if (err) {
log.warn('Error occurred when connecting to database. ' + err);
}
});
What could be the reason for this? Could this be due to something wrong with the database? Is there any way I can further troubleshoot this?