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

When I tried to deploy my backend server on render, it is showing this error. In my localhost, it is working properly.

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.
NativeConnection.Connection.openUri (/opt/render/project/src/node_modules/mongoose/lib/connection.js:694:11)
/opt/render/project/src/node_modules/mongoose/lib/index.js:351:10
/opt/render/project/src/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
Oct 16 09:57:58 AM at new Promise ()
Oct 16 09:57:58 AM at promiseOrCallback (/opt/render/project/src/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
Oct 16 09:57:58 AM at Mongoose._promiseOrCallback (/opt/render/project/src/node_modules/mongoose/lib/index.js:1149:10)
Oct 16 09:57:58 AM at Mongoose.connect (/opt/render/project/src/node_modules/mongoose/lib/index.js:350:20)
Oct 16 09:57:58 AM at Object. (/opt/render/project/src/backend/app.js:43:10)
Oct 16 09:57:58 AM at Module._compile (internal/modules/cjs/loader.js:1068:30)
Oct 16 09:57:58 AM at Object.Module._extensions…js (internal/modules/cjs/loader.js:1097:10)
Oct 16 09:57:58 AM at Module.load (internal/modules/cjs/loader.js:933:32)
Oct 16 09:57:58 AM at Function.Module._load (internal/modules/cjs/loader.js:774:14)
Oct 16 09:57:58 AM at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Oct 16 09:57:58 AM at internal/main/run_main_module.js:17:47

Hi,

From the basis of that error, you’ll need to ensure that wherever you define your Mongo URI, it’s correct and read by your code as expected.

Alan

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