MongoDB Model.find() does not work inside if conditional branch?

you need some changes in your project :

  1. update mongoose version to 5.8.11.when you update mongoose version, in the console you will see some warnings, to remove these warnings remove {useMongoClient:true} form mongoose.connect() function and add {useNewUrlParser: true,useUnifiedTopology:true} to your connection i.e.
mongoose.connect(process.env.MONGO_URI,  {useNewUrlParser: true, useUnifiedTopology:true}); 

it will remove all warnings.
now start your MONGO_URI with +srv as follows :

MONGO_URI="mongodb+srv://"

(note: store your MONGO_URI inside .env file so nobody can see your MONGO_URI).

after changing above code the result in console when submit url is:

find : 
find : 

anURL.find() returns value of urlFind as empty ,because you have not save any data to your collection yet.

1 Like