troubleshooting Question

Docker / Node -> Can't Connect to Database. Why?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
JavaScriptDockerNode.js
6 Comments1 Solution102 ViewsLast Modified:
I'm new to Docker.

I'm working with an app that's got a Dockerfile and all of the bells and whistles that should fire up immediately assuming I've got Docker installed, which I do.

But I can't connect to my database and the thing that's galling is that it says it's "undefined..."

b.gust@AHA-DT-BGUST2 MINGW64 /c/wamp64/www/bSmart (code-cleanup)
$ yarn start
yarn run v1.19.1
$ sh ./bin/start.sh
./bin/start.sh: line 3: [: =: unary operator expected
(node:37640) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
User and company already exist: {"_id":"5e2a0b8b374a731400c45b9b"}
You may log in with email accounts@appliedhealth.net and password C@tch0fTheDay!
Start making of the Form 5500 Collections.
C:\wamp64\www\bSmart\bin\create-f5500:14
  throw new Error(`unable to connect to database: ${mongoUri}`);
  ^

Error: unable to connect to database: undefined/undefined
    at NativeConnection.<anonymous> (C:\wamp64\www\bSmart\bin\create-f5500:14:9)
    at NativeConnection.emit (events.js:210:5)
    at C:\wamp64\www\bSmart\node_modules\mongoose\lib\connection.js:832:37
    at processTicksAndRejections (internal/process/task_queues.js:75:11)
[nodemon] 2.0.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json,twig
[nodemon] starting `node index.js`
(node:33528) UnhandledPromiseRejectionWarning: MongoWriteConcernError: No write concern mode named 'majority/dev-bsmart-bgust' found in replica set configuration
    at MessageStream.messageHandler (C:\wamp64\www\bSmart\node_modules\mongoose\node_modules\mongodb\lib\cmap\connection.js:256:20)
    at MessageStream.emit (events.js:210:5)
    at processIncomingData (C:\wamp64\www\bSmart\node_modules\mongoose\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
    at MessageStream._write (C:\wamp64\www\bSmart\node_modules\mongoose\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
    at doWrite (_stream_writable.js:431:12)
    at writeOrBuffer (_stream_writable.js:415:5)
    at MessageStream.Writable.write (_stream_writable.js:305:11)
    at TLSSocket.ondata (_stream_readable.js:727:22)
    at TLSSocket.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at TLSSocket.Readable.push (_stream_readable.js:224:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:182:23)
(node:33528) 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(). (rejection id: 1)
(node:33528) [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..

throw new Error(`unable to connect to database: ${mongoUri}`);

I've run this app before in the context of a different branch, so I'm certain the database name and credentials are credible, yet I can't connect and I don't know why.

I have this in my config.js file:

// require and configure dotenv, will load vars in .env in PROCESS.ENV
require('dotenv').config();


So, that gives me every reason to believe that my credentials are going to be coming from the .env file and I'm certain the right creds are documented. Still, no connection. Why?

What am I missing? Where else can I look?

Thanks!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros