MongoDB and Mongoose - Install and Set Up Mongoose

Tell us what’s happening:

When trying to start the connection with the Mongo db I continuously get this error message:

(node:1365) [DEP0170] DeprecationWarning: The URL mongodb://user:password@ac-c0tkbpu-shard-00-00.8qlweyy.mongodb.net:27017,ac-c0tkbpu-shard-00-01.8qlweyy.mongodb.net:27017,ac-c0tkbpu-shard-00-02.8qlweyy.mongodb.net:27017/?authSource=admin&replicaSet=atlas-j472zl-shard-0&retryWrites=true&w=majority&appName=Cluster0&ssl=true is invalid. Future versions of Node.js will throw an error.
(obviously in the 'real 'version of this message user and password are my username and password).

I have done the folowing:

  1. created the .env file and pasted the connect string provided by Mongodb to a var called MONGO_URI
    MONGO_URI=“mongodb+srv://user:password@cluster0.8qlweyy.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0”
    (again, user and password are of course filled in).

  2. created the mongoose variable:
    const mongoose = require(‘mongoose’);

  3. tried to connect mongoose to the Mongodb database:

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })

The result is the error message given above.

No idea what to do here.

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0

Challenge Information:

MongoDB and Mongoose - Install and Set Up Mongoose

Even though the same error message keeps popping up, it seems that the script is working, as the tests are passed.

Still would like to know what the error message means though.

It has to do with Node 20 and the old Mongoose version used (MongoDB driver version pinned by it).

It should go away if you update Mongoose npm i mongoose@latest

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.