kunalkapadia / express-mongoose-es6-rest-api

:collision: A boilerplate application for building RESTful APIs Microservice in Node.js using express and mongoose in ES6 with code coverage and JsonWebToken Authentication
http://kunalkapadia.github.io/express-mongoose-es6-rest-api/
MIT License
2.94k stars 694 forks source link

Invalid database name #315

Open beyer-martin opened 7 years ago

beyer-martin commented 7 years ago

Cannot get api to work, changed the database name to one that i created on mongo and this error pops "message": "Internal Server Error", "stack": "Error: Invalid database name: 'vsv:27017'

kunalkapadia commented 7 years ago

@beyersito Can you please attach a screenshot ? Also can you let me know where exactly in code did you update the db name ?

beyer-martin commented 7 years ago

image image

I went to default config

kunalkapadia commented 7 years ago

@beyersito Were you able to start the server successfully ? Can you send me logs ?

I just took latest from master and did npm run start:debug and was able to access GET http://localhost:4040/api/users.

beyer-martin commented 7 years ago

I am using yarn, maybe thats the problem?

kunalkapadia commented 7 years ago

@beyersito No that shouldn't be a issue at all. Can you please send startup logs ?

beyer-martin commented 7 years ago

Where can I find them?

kunalkapadia commented 7 years ago

@beyersito When you run yarn start:debug or npm run start:debug on terminal, what logs do you get ?

beyer-martin commented 7 years ago

npm run start:debug

express-mongoose-es6-rest-api@2.0.0 start:debug D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api cross-env DEBUG=express-mongoose-es6-rest-api:* yarn start

yarn start v0.20.3 $ gulp serve [14:57:56] Requiring external module babel-register [14:57:56] Using gulpfile D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\gulpfile.babel.js [14:57:56] Starting 'clean'... [14:57:56] Finished 'clean' after 54 ms [14:57:56] Starting 'serve'... [14:57:56] Starting 'copy'... [14:57:57] Starting 'babel'... [14:57:57] Finished 'serve' after 345 ms [14:58:00] Finished 'copy' after 3.27 s [14:58:00] Finished 'babel' after 3.47 s [14:58:00] Starting 'nodemon'... [14:58:00] Finished 'nodemon' after 187 ms [14:58:00] [nodemon] 1.11.0 [14:58:00] [nodemon] to restart at any time, enter rs [14:58:00] [nodemon] watching: . [14:58:00] [nodemon] starting node dist\index.js Fri, 24 Feb 2017 17:58:03 GMT express-mongoose-es6-rest-api:index server started on port 4040 (development) { "date": "Fri Feb 24 2017 14:58:10 GMT-0300 (Hora estándar de Montevideo)", "process": { "pid": 16500, "uid": null, "gid": null, "cwd": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api", "execPath": "D:\Program Files\nodejs\node.exe", "version": "v6.9.5", "argv": [ "D:\Program Files\nodejs\node.exe", "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\index.js" ], "memoryUsage": { "rss": 63873024, "heapTotal": 65024000, "heapUsed": 34782344 } }, "os": { "loadavg": [ 0, 0, 0 ], "uptime": 151606.5921943 }, "trace": [ { "column": 11, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\helpers\APIError.js", "function": "APIError.ExtendableError", "line": 35, "method": "ExtendableError", "native": false }, { "column": 101, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\helpers\APIError.js", "function": "new APIError", "line": 63, "method": null, "native": false }, { "column": 20, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\config\express.js", "function": null, "line": 114, "method": null, "native": false }, { "column": 5, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\layer.js", "function": "Layer.handle_error", "line": 71, "method": "handle_error", "native": false }, { "column": 13, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js", "function": "trim_prefix", "line": 310, "method": null, "native": false }, { "column": 7, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js", "function": null, "line": 280, "method": null, "native": false }, { "column": 12, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js", "function": "Function.process_params", "line": 330, "method": "process_params", "native": false }, { "column": 10, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js", "function": "next", "line": 271, "method": null, "native": false }, { "column": 15, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js", "function": null, "line": 618, "method": null, "native": false }, { "column": 14, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js", "function": "next", "line": 256, "method": null, "native": false }, { "column": 15, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js", "function": null, "line": 618, "method": null, "native": false }, { "column": 14, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js", "function": "next", "line": 256, "method": null, "native": false }, { "column": 14, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\route.js", "function": "next", "line": 121, "method": null, "native": false }, { "column": 14, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\route.js", "function": "next", "line": 125, "method": null, "native": false }, { "column": 14, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\route.js", "function": "next", "line": 125, "method": null, "native": false }, { "column": 12, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\controllers\user.controller.js", "function": null, "line": 86, "method": null, "native": false }, { "column": 23, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\util.js", "function": "tryCatcher", "line": 16, "method": null, "native": false }, { "column": 31, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js", "function": "Promise._settlePromiseFromHandler", "line": 510, "method": "_settlePromiseFromHandler", "native": false }, { "column": 18, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js", "function": "Promise._settlePromise", "line": 567, "method": "_settlePromise", "native": false }, { "column": 10, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js", "function": "Promise._settlePromise0", "line": 612, "method": "_settlePromise0", "native": false }, { "column": 18, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js", "function": "Promise._settlePromises", "line": 687, "method": "_settlePromises", "native": false }, { "column": 16, "file": "D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\async.js", "function": "Async._drainQueue", "line": 138, "method": "_drainQueue", "native": false } ], "stack": [ "Error: Invalid database name: 'express-mongoose-es6-rest-api-development:27017'", " at APIError.ExtendableError (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\helpers\APIError.js:35:11)", " at new APIError (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\helpers\APIError.js:63:101)", " at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\config\express.js:114:20", " at Layer.handle_error (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\layer.js:71:5)", " at trim_prefix (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:310:13)", " at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:280:7", " at Function.process_params (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:330:12)", " at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:271:10)", " at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:618:15", " at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:256:14)", " at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:618:15", " at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:256:14)", " at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\route.js:121:14)", " at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\route.js:125:14)", " at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\route.js:125:14)", " at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\controllers\user.controller.js:86:12", " at tryCatcher (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\util.js:16:23)", " at Promise._settlePromiseFromHandler (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js:510:31)", " at Promise._settlePromise (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js:567:18)", " at Promise._settlePromise0 (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js:612:10)", " at Promise._settlePromises (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js:687:18)", " at Async._drainQueue (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\async.js:138:16)" ], "req": { "url": "/api/users", "headers": { "host": "localhost:4040", "connection": "keep-alive", "cache-control": "no-cache", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", "postman-token": "c460eac6-7507-6326-21ee-0c73ea3e078f", "accept": "/", "accept-encoding": "gzip, deflate, sdch, br", "accept-language": "en-US,en;q=0.8,es-419;q=0.6,es;q=0.4" }, "method": "GET", "httpVersion": "1.1", "originalUrl": "/api/users", "query": {}, "body": {} }, "level": "error", "message": "middlewareError" } { "res": { "statusCode": 500, "body": { "message": "Internal Server Error", "stack": "Error: Invalid database name: 'express-mongoose-es6-rest-api-development:27017'\n at APIError.ExtendableError (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\helpers\APIError.js:35:11)\n at new APIError (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\helpers\APIError.js:63:101)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\config\express.js:114:20\n at Layer.handle_error (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\layer.js:71:5)\n at trim_prefix (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:310:13)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:280:7\n at Function.process_params (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:330:12)\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:271:10)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:618:15\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:256:14)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:618:15\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:256:14)\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\route.js:121:14)\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\route.js:125:14)\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\route.js:125:14)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\controllers\user.controller.js:86:12\n at tryCatcher (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\util.js:16:23)\n at Promise._settlePromiseFromHandler (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js:510:31)\n at Promise._settlePromise (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js:567:18)\n at Promise._settlePromise0 (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js:612:10)\n at Promise._settlePromises (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\promise.js:687:18)\n at Async._drainQueue (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\bluebird\js\release\async.js:138:16)" } }, "req": { "url": "/api/users", "headers": { "host": "localhost:4040", "connection": "keep-alive", "cache-control": "no-cache", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", "postman-token": "c460eac6-7507-6326-21ee-0c73ea3e078f", "accept": "/", "accept-encoding": "gzip, deflate, sdch, br", "accept-language": "en-US,en;q=0.8,es-419;q=0.6,es;q=0.4" }, "method": "GET", "httpVersion": "1.1", "originalUrl": "/api/users", "query": {} }, "responseTime": 57, "level": "info", "message": "HTTP GET /api/users 500 57ms" }

kunalkapadia commented 7 years ago

@beyersito That's very weird. Also after starting the server, Can you tell me the response you get when you hit http://localhost:4040/api/health-check ?

I am trying on Mac, something might be wrong when running on windows. Can you remove the PORT and try again?

beyer-martin commented 7 years ago

Of which port are talking about?

I get this at that route

{ "message": "Not Found", "stack": "Error: API not found\n at APIError.ExtendableError (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\helpers\APIError.js:35:11)\n at new APIError (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\server\helpers\APIError.js:63:101)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\dist\config\express.js:122:13\n at Layer.handle [as handle_request] (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\layer.js:95:5)\n at trim_prefix (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:312:13)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:280:7\n at Function.process_params (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:330:12)\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:271:10)\n at Layer.handle [as handle_request] (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\layer.js:91:12)\n at trim_prefix (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:312:13)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:280:7\n at Function.process_params (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:330:12)\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:271:10)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:618:15\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:256:14)\n at Function.handle (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:176:3)\n at router (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:46:12)\n at Layer.handle [as handle_request] (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\layer.js:95:5)\n at trim_prefix (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:312:13)\n at D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:280:7\n at Function.process_params (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:330:12)\n at next (D:\Users\Beyersito\Documents\Vixur\VSV\api\express-mongoose-es6-rest-api\node_modules\express\lib\router\index.js:271:10)" }

kunalkapadia commented 7 years ago

@beyersito Are you sure you have taken latest from master branch ?

curl http://localhost:4040/api/health-check should return OK if server is healthy.

DennisKo commented 7 years ago

I was getting the same error on windows 10.

Delete the port part on line 17 in index.js:

const mongoUri = `${config.mongo.host}`;

wassimz commented 7 years ago

@KunalKapadia I got the same issue on Windows 7 and applying the solution mentioned by @DennisKo solved it (removing the port field for the mongoUri)

ArthurJahn commented 7 years ago

Guess that for newer versions of mongodb, the ports are specified before database name. mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]. See: https://docs.mongodb.com/manual/reference/connection-string/

set mongoUri in index.js

const mongoUri = `${config.mongo.host}:${config.mongo.port}/${config.mongo.dbname}`;

format your .env file as follows:

NODE_ENV=development
PORT=4040
JWT_SECRET=0a6b944d-d2fb-46fc-a85e-0295c986cd9f
MONGO_HOST=mongodb://localhost
MONGO_PORT=27017
MONGO_DBNAME=<db-name>

And add your MONGO_DBNAME env var to config.js:

  ...
  // validation
  MONGO_HOST: Joi.string().required()
    .description('Mongo DB host url'),
  MONGO_PORT: Joi.number().default(27017),
  MONGO_DBNAME: Joi.string()
  ...
  // config 
  mongo: {
    host: envVars.MONGO_HOST,
    port: envVars.MONGO_PORT,
    dbname: envVars.MONGO_DBNAME
  }

this solved the issue for me.

paulohfcanuto commented 7 years ago

I had the same problem on windows 10, Thx @ArthurJahn!!!

aravindhkm commented 4 years ago

i had the same problem on ubuntu , pls help me @kunalkapadia

ArthurJahn commented 4 years ago

Guess that for newer versions of mongodb, the ports are specified before database name. mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]. See: https://docs.mongodb.com/manual/reference/connection-string/

set mongoUri in index.js

const mongoUri = `${config.mongo.host}:${config.mongo.port}/${config.mongo.dbname}`;

format your .env file as follows:

NODE_ENV=development
PORT=4040
JWT_SECRET=0a6b944d-d2fb-46fc-a85e-0295c986cd9f
MONGO_HOST=mongodb://localhost
MONGO_PORT=27017
MONGO_DBNAME=<db-name>

And add your MONGO_DBNAME env var to config.js:

  ...
  // validation
  MONGO_HOST: Joi.string().required()
    .description('Mongo DB host url'),
  MONGO_PORT: Joi.number().default(27017),
  MONGO_DBNAME: Joi.string()
  ...
  // config 
  mongo: {
    host: envVars.MONGO_HOST,
    port: envVars.MONGO_PORT,
    dbname: envVars.MONGO_DBNAME
  }

this solved the issue for me.

Have you tried this?