My MongoDB was working fine but at some point, I was facing issues to connect my express server with the DB. when I start the DB using mongod it shows me 2020-05-21T14:36:41.819+0600 I NETWORK [initandlisten] waiting for connections on port 27017 which seems like a normal "running" entry. Then I run my express server where I connect the DB like this:
...
const mongoose = require('mongoose');
const url = 'mongodb://localhost:27017/db_name';
const connect = mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
});
connect.then(
(db) => {
console.log('Connected correctly to server');
},
(err) => {
console.log(err);
}
);
...
which log Connected correctly to server but when I see the mongod running shell then there still the message which showed that it still waiting for the connection. And the most surprising issue is I can perform database related work in my express server. when I check the document using mongo, I see they correctly added to the database. I can't understand then why mongod behave like this. here is the full log of the mongod shell.
Update:
I forgot to add one important piece of information which is whenever I start my MongoDB server using mongod, in the C:\data\db directory there generate a new mongod.lock file. I tried to delete it and restart my server but eventually it generates again.