0

Recently I am using docker container where I have installed node.JS project, But I did not mention or used MongoDB image in docker container, I would like to connect hosted MongoDB Database using URL. We have made MongoDB URL and put it inside the .env file but it doesn't connect to the MongoDB database. But If I use MongoDB Atlas/cloud link it works. Is there any option to connect it this way?

here is my Docker code for the server below

FROM node:14.5.0
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
EXPOSE 9000
CMD ["npm","start"]

Md Rezaul Karim
  • 508
  • 7
  • 17
  • Can you post an error message or some logging? Also some information about how your mongo server is setup and how you are connecting to it would be helpful. – kthompso Aug 05 '21 at 17:50
  • it shows timeout error. Here is my connection setup ``` const mongoose=require('mongoose'); const config=require('../config/key') mongoose.connect(config.mongoURL, {useNewUrlParser:true, useUnifiedTopology: true }).then(()=> console.log("Mongo DB connected") ) .catch(err=> console.log(err)); ``` Here is my environment variable ``` mongodb://:@:27017/?authSource=admin ``` – Md Rezaul Karim Aug 06 '21 at 05:28

0 Answers0