I tried older versions of Mongoose and MongoDB. There, the connection was successful only once and then I started getting the same error. Then I updated to the latest version and the problem fixed itself. I didn’t understand anything, but my problem resolved itself.