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 NativeConnection.createClient (C:UsersHPDesktopBookStorebackendnode_modulesmongooselibdriversnode-mongodb-nativeconnection.js:219:11)
at NativeConnection.openUri (C:UsersHPDesktopBookStorebackendnode_modulesmongooselibconnection.js:823:34)
at Mongoose.connect (C:UsersHPDesktopBookStorebackendnode_modulesmongooselibmongoose.js:448:15)
at conn (file:///C:/Users/HP/Desktop/BookStore/backend/connection/conn.js:7:20)
at file:///C:/Users/HP/Desktop/BookStore/backend/app.js:14:1
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Server is running on port 8080
I want to setup my database:
1
As the error message states, you need to make sure that you pass a string
of the database URI to mongoose.connect()
. You can obtain the database URI by going to your MongoDB cluster on the MongoDB website and clicking Connect
. The URI should start with this:
mongodb+srv://<db_username>:<db_password>@<cluster_name>...
In your call to mongoose.connect()
, include the URI like so:
await mongoose.connect('<your database URI here>');
You can also take a look at:
- Mongoose documentation on connections
- Mozilla tutorial on connecting to MongoDB with mongoose