aditya bonde
aditya bonde

Reputation: 11

Getting error while connecting mongo db, how to solve it?

MongooseError: The uri parameter to openUri() must be a string, got "undefined". Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string. at _createMongoClient

not able to connect mongodb Some code

1

my env file

2

connecting the mongo db

Upvotes: 1

Views: 644

Answers (1)

Krushnal Patel
Krushnal Patel

Reputation: 454

Couple of points:

  1. You have to access the env variable using process.env.ENV_VARIABLE_NAME?
  2. For accessing the env variable, you have to load the env variables from .env file into process.env using some library like dotenv
  3. You have to give a name to the env variable making it a key value pair after which it will be loaded into process.env under the name of the variable. eg.

.env file

MONGODB_URI=mongo+srv://Aditya........
  1. You have not properly written the password in the connection string. The password can not be ******. You have to remove the asterisks and replace them with the password you generated manually or had MongoDB generate automatically while creating the database. If you don't have the password which can only be seen once, go to database user settings, add another user or edit the current user to update the password and then copy it once and store it somewhere

Upvotes: 0

Related Questions