Install and Set Up Mongoose Problems

Hi,

I’ve just started the MongoDB section of the Back End & API section and I’ve hit a brick wall.

MongoDB and Mongoose - Install and Set Up Mongoose | Learn | freeCodeCamp.org

I’ve followed the guide here to the letter:

MongoDB Atlas Tutorial – How to Get Started (freecodecamp.org)

When I get to “Connect to Your Cluster”, there seems to be a disconnect between what I see and what the tutorial implies I should be seeing. The connection string I’m provided on MongoDB looks like this:

mongodb+srv://GregoryW:<password>@mongodbexercises.bea1kb6.mongodb.net/?retryWrites=true&w=majority

The tutorial implies it should be like this:

mongodb+srv://<username>:<password>@<cluster-name>.prx1c.mongodb.net/<db-name>?retryWrites=true&w=majority

My provided connection string is missing “db-name” and there is nothing on MongoDB’s website to suggest that something should go there. However, if I leave this area blank I get an database name error on Replit. Putting anything here clears that error and I can pass the challenge.

Do I need to add the cluster name here, or do I need to create a database within the cluster manually and put that name in the connection string (this isn’t part of the setup tutorial as far as I can see)? Or do I just put any name here and it sorts itself out?

Secondly, I cannot for the life of me clear this error, regardless of what I do:

the options [useUnifiedTopology] is not supported
(node:514) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:514) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
(node:514) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
(node:514) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
Your app is listening on port 3000

Replit raw secrets editor:

{
  "MONGO_URI": "mongodb+srv://GregoryW:hidden@mongodbexercises.bea1kb6.mongodb.net/?retryWrites=true&w=majority"
}

myApp.js:

const mongoose = require('mongoose')

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

Any help would be much appreciated!

Okay, I’ve answered my first question.

Just putting a random name in that space seems to create the appropriate database within my MongoDB cluster in a later exercise (Create and Save a Record of a Model). It’s still a little confusing that MongoDB seemingly no longer provide a connection string with a placeholder for “db-name”. I’m guessing things may have changed behind the scenes recently, as all of the examples I’ve seen still have this placeholder and instructions to replace it, like the password.

My second problem ([useUnifiedTopology] error) still stands, however.

Just remove that option in the .connect.