Install and Setup Mongoose Errors

Hello, I keep getting errors when running my replit and the freecodecamp marker keeps saying that “mongoose” is not connected to a database
Here is a copy paste of the error:
(node:1735) UnhandledPromiseRejectionWarning: 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.Connection.openUri (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/connection.js:694:11)
at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:351:10
at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise ()
at promiseOrCallback (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:1149:10)
at Mongoose.connect (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:350:20)
at Object. (/home/runner/boilerplate-mongomongoose/myApp.js:6:10)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/runner/boilerplate-mongomongoose/server.js:67:16)
at Module._compile (internal/modules/cjs/loader.js:999:30)
(node:1735) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To ter
 npm start

fcc-mongo-mongoose-challenges@0.0.1 start /home/runner/boilerplate-mongomongoose
node server.js

Your app is listening on port 3000
(node:1811) UnhandledPromiseRejectionWarning: 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.Connection.openUri (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/connection.js:694:11)
at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:351:10
at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise ()
at promiseOrCallback (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:1149:10)
at Mongoose.connect (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:350:20)
at Object. (/home/runner/boilerplate-mongomongoose/myApp.js:6:10)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/runner/boilerplate-mongomongoose/server.js:67:16)
at Module._compile (internal/modules/cjs/loader.js:999:30)
(node:1811) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see Command-line API | Node.js v21.2.0 Documentation). (rejection id: 1)
(node:1811) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Here is my replit:

( I replaced the user and password with and when sharing this, but I still get errors when replacing and with the values for my database

stack error said uri parameter must be a string, got “undefined”

click the padlock, fill in the key value pair there. the key is MONGO_URI, the value should be the string you got from mongoDB. No space, no quotes. Change the <username> and <password> with your real ones. Change myFirstDatabase with your real database name.

Use the given variable at the bottom of the padlock: mySecret as the variable for the mongoose.connect, or just simply use process.env[“MONGO_URI”] there

1 Like

thanks for the help, it works now!

1 Like

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