Chapter0: setting up readme: I am geting some warning while executing npm start command

(node:2808) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

(Use node --trace-warnings ... to show where the warning was created)

So can someone plz tell me where to change useUnifiedTopology in mongoClient constructor

$ node --trace-warnings ...

internal/modules/cjs/loader.js:888
throw err;
^

Error: Cannot find module ‘D:\mflix_mongodb…’
←[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:730:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m {
code: ←[32m’MODULE_NOT_FOUND’←[39m,
requireStack: []
}

This is what I get when I trace the source of my warnings, hope this helps u to solve my query

HI @Adithya_Shetty, you need to update the MongoClient constructor as mentioned in the warning message. You can refer to the following syntax to get a better idea of what needs to be done in order to fix the issue:

new MongoClient("----Your connection string----", { useUnifiedTopology: true });

Please note the { useUnifiedTopology: true } option mentioned above. I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks & Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

1 Like

just one doubt, do I need to remove this code from the constructor: { useNewUrlParser: true }
and could u plz tell me why the warning is caused, and what UnifiedTopology and UrlParser are used for??

And when I connect to localhost:5000 why am I getting this, {“error”: “not found”} even though its listening on port 5000,
and I am getting this error after refreshing screen
GET / 404 3.200 ms - 21

Hi @Adithya_Shetty, no you don’t need to remove anything, but you have to add the object { useNewUrlParser: true } as mentioned above.
Also, to answer why it is occurring:

The legacy topologies have a “fast fail” mode where connect will return immediately is some network error has occurred (invalid uri, ssl options, etc). The unified topology implements connect as a “server selection” which means it will wait up to serverSelectionTimeoutMS before failing to connect, so the short answer to your question is that you want to reduce that value (either through the connection string, or MongoClient options) to fail faster.

You can also learn more, by following the discussion here: useUnifiedTopology test failed

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

1 Like

Thank u…I found this constructor in index.js and corrected it