menu

JS Everywhere

A community for the JavaScript Everywhere book by Adam Scott, published by O'Reilly.

Channels
Team

Problem with mongoose.connect

May 17, 2020 at 9:54pm

Problem with mongoose.connect

May 17, 2020 at 9:54pm (Edited 3 months ago)
I receive an error message stating it is expecting a string in mongoose.connect(). Should I add my local host in a string or use DB_HOST connect to my .env file?
C:\Users\qu0es\Desktop\Projects\notedly\node_modules\mongoose\lib\connection.js:541 throw new MongooseError('The uri parameter to openUri() must be a ' + ^ Error [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 new MongooseError (C:\Users\qu0es\Desktop\Projects\notedly\node_modules\mongoose\lib\error\mongooseError.js:10:11) at NativeConnection.Connection.openUri (C:\Users\qu0es\Desktop\Projects\notedly\node_modules\mongoose\lib\connection.js:541:11) at Mongoose.connect (C:\Users\qu0es\Desktop\Projects\notedly\node_modules\mongoose\lib\index.js:328:15) at Object.connect (C:\Users\qu0es\Desktop\Projects\notedly\src\db.js:15:14) at Object.<anonymous> (C:\Users\qu0es\Desktop\Projects\notedly\src\index.js:74:4) at Module._compile (internal/modules/cjs/loader.js:1158:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10) at Module.load (internal/modules/cjs/loader.js:1002:32) at Function.Module._load (internal/modules/cjs/loader.js:901:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) at internal/main/run_main_module.js:18:47 { message: '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.', name: 'MongooseError'

May 18, 2020 at 5:34am
Hi, I guess you should have the next value in your .env file:
Database
DB_HOST=mongodb://127.0.0.1:27017 (or the location of your mongodb instance). Hope this works well for you
  • reply
  • like
Hi ! suggestion is spot on (thanks!) - make sure you have the value of your local MongoDB host instance in your .env file
  • reply
  • like