Code Monkey home page Code Monkey logo

Comments (2)

carrodher avatar carrodher commented on August 23, 2024

The issue may not be directly related to the Bitnami container image/Helm chart, but rather to how the application is being utilized, configured in your specific environment, or tied to a specific scenario that is not easy to reproduce on our side.

If you think that's not the case and are interested in contributing a solution, we welcome you to create a pull request. The Bitnami team is excited to review your submission and offer feedback. You can find the contributing guidelines here.

Your contribution will greatly benefit the community. Feel free to reach out if you have any questions or need assistance.

Suppose you have any questions about the application, customizing its content, or technology and infrastructure usage. In that case, we highly recommend that you refer to the forums and user guides provided by the project responsible for the application or technology.

With that said, we'll keep this ticket open until the stale bot automatically closes it, in case someone from the community contributes valuable insights.

from charts.

G0ldan avatar G0ldan commented on August 23, 2024

I found a solution to my problem. Here are the details:

Environment variables in the .env file:

# MONGO
MONGO_HOST=127.0.0.1
MONGO_PORT=3001
MONGO_DB_NAME=MyApp
MONGO_USER=admin
MONGO_PASSWORD=password
MONGO_SECONDARY_KEY=X5ZxqCt4cQrQ3Zfr2zRBFk8R0eakYBaH

# MONGO EXPRESS
MONGO_EXPRESS_PORT=8080
MONGO_EXPRESS_AUTH_USERNAME=admin
MONGO_EXPRESS_AUTH_PASSWORD=password

Here's a sample of the Node.js connection code where I've added &directConnection=true to the mongodb url that fix the problem.

import mongoose from "mongoose"
import dotenv from "dotenv"

dotenv.config()

export const db_connect = async () => {
  console.log("Connecting to MongoDB...")

  const db = await mongoose.connect(
    `mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@${process.env.MONGO_HOST}:${process.env.MONGO_PORT}/${process.env.MONGO_DB_NAME}?authSource=admin&directConnection=true`
  )

  console.log("Connected to MongoDB")
}

db_connect()

Here's the complete Docker Compose file:

version: "3.9"

services:
  mongodb:
    image: bitnami/mongodb:latest
    ports:
      - "${MONGO_PORT}:${MONGO_PORT}"
    environment:
      MONGODB_ADVERTISED_HOSTNAME: ${MONGO_HOST}
      MONGODB_ADVERTISED_PORT_NUMBER: ${MONGO_PORT}
      MONGODB_PORT_NUMBER: ${MONGO_PORT}
      MONGODB_ROOT_USER: ${MONGO_USER}
      MONGODB_ROOT_PASSWORD: ${MONGO_PASSWORD}
      MONGODB_REPLICA_SET_MODE: primary
      MONGODB_REPLICA_SET_KEY: ${MONGO_SECONDARY_KEY}
    volumes:
      - ./database:/bitnami/mongodb

  mongo-express:
    image: mongo-express:latest
    ports:
      - "8081:8081"
    environment:
      ME_CONFIG_MONGODB_URL: mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongodb:${MONGO_PORT}
      ME_CONFIG_BASICAUTH_USERNAME: ${MONGO_EXPRESS_AUTH_USERNAME}
      ME_CONFIG_BASICAUTH_PASSWORD: ${MONGO_EXPRESS_AUTH_PASSWORD}
    depends_on:
      - mongodb
    restart: unless-stopped

from charts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.