@Tahmid_Khandokar Some details:
Mongoose lets you start using your models immediately, without waiting for mongoose to establish a connection to MongoDB.
That’s because mongoose buffers model function calls internally. This buffering is convenient, but also a common source of confusion. Mongoose will not throw any errors by default if you use a model without connecting.
User.find() is a Model.method() call, and it has a timeout. It is timing out probably because you’re not connecting to the server, but mongoose throws no errors.
You can disable buffering, but it is probably not advisable (it is on by default, so for simple projects it may be the right setting).
But you could at least set a handler for the error event. basically, it is this:
mongoose.connect(
process.env.MONGO_URL,
options,
(err) => {
if(err) console.log(err)
else console.log("mongdb is connected");
}
);
// or
mongoose.connect(
process.env.MONGO_URL,
options
)
.then(()=>console.log('connected'))
.catch(e=>console.log(e));
Or using async/try/catch.
You’ll find out what the error is (I believe).