1

When I try to run a Docker container and connect to a local MongoDB database, it gives me this error:

UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Authentication failed.

this is the connection url in the end: mongodb://pody-admin:Nt4VzWPtDhkCxESjXVJx@localhost:27017/podify

I am trying to get an Auth system that someone else made to work on my end(cloned the repo).

I really don't have experience with working on team projects and using other people's code, let alone Docker.

I'm not really expecting a solution, but would like to know where to look to even understand what might be wrong.

This is what I get in the cmd:

$ npm run up

server@1.0.0 up D:\projects\SOS\podify\Server docker-compose up -d

Starting server_db_1 ... done Starting server_cache_1 ... done

server@1.0.0 postup D:\projects\SOS\podify\Server npm run dev

server@1.0.0 dev D:\projects\SOS\podify\Server npm run dev --prefix api

api@1.0.0 dev D:\projects\SOS\podify\Server\api nodemon --exec ts-node src/index.ts

[nodemon] 2.0.4 [nodemon] to restart at any time, enter rs [nodemon] watching path(s): . [nodemon] watching extensions: ts,json [nodemon] starting ts-node src/index.ts

Connection url => mongodb://pody-admin:Nt4VzWPtDhkCxESjXVJx@localhost:27017/podify

(node:5072) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Authentication failed. at NativeConnection.Connection.openUri (D:\projects\SOS\podify\Server\api\node_modules\mongoose\lib\connection.js:828:32) at Mongoose.connect (D:\projects\SOS\podify\Server\api\node_modules\mongoose\lib\index.js:335:15) at D:\projects\SOS\podify\Server\api\src\index.ts:10:20 at Object. (D:\projects\SOS\podify\Server\api\src\index.ts:21:3) at Module._compile (internal/modules/cjs/loader.js:1137:30) at Module.m._compile (D:\projects\SOS\podify\Server\api\node_modules\ts-node\src\index.ts:858:23) at Module._extensions..js (internal/modules/cjs/loader.js:1157:10) at Object.require.extensions. [as .ts] (D:\projects\SOS\podify\Server\api\node_modules\ts-node\src\index.ts:861:12) at Module.load (internal/modules/cjs/loader.js:985:32) at Function.Module._load (internal/modules/cjs/loader.js:878:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at main (D:\projects\SOS\podify\Server\api\node_modules\ts-node\src\bin.ts:227:14) at Object. (D:\projects\SOS\podify\Server\api\node_modules\ts-node\src\bin.ts:513:3) at Module._compile (internal/modules/cjs/loader.js:1137:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10) at Module.load (internal/modules/cjs/loader.js:985:32) (node:5072) 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 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:5072) [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. [nodemon] clean exit - waiting for changes before restart

  • Your app is running in a container, when you tell it to connect to `localhost`, it is trying to connect to a mongodb instance in your container, which won't work because there's none. [This](https://stackoverflow.com/questions/40746453/how-to-connect-to-docker-host-from-container-on-windows-10-docker-for-windows) should help you. – snahor Sep 07 '20 at 18:15

0 Answers0