mongo-express-docker icon indicating copy to clipboard operation
mongo-express-docker copied to clipboard

Connect to CosmosDB in Azure

Open shulevas opened this issue 3 years ago • 1 comments

Hi! Is there a way using mongo-express-docker to connect to CosmosDB in Azure? For this, a link of the following form is used: mongodb://username:password@host:port/[database]?ssl=true

I know there is a parameter ME_CONFIG_MONGODB_URL, but when using it I still need to specify something in the ME_CONFIG_MONGODB_SERVER and ME_CONFIG_MONGODB_PORT parameters. It looks like parameter ME_CONFIG_MONGODB_URL is not working.

shulevas avatar Mar 30 '21 10:03 shulevas

After tinkering around with it for a while, I managed to run mongo-express with Azure Cosmos DB. For the connection string, be sure to copy the "Node.js 3.0" one from the azure portal.

I am using docker and here is my docker-compose.yml

services:
    # run mongo-express targeting the Azure Cosmos DB
    mongoex:
      image: mongo-express
      environment:
        - ME_CONFIG_MONGODB_SERVER=
        - ME_CONFIG_MONGODB_URL=mongodb://user:pass@server:port/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@app-name@
      volumes:
        - "./config.js:/node_modules/mongo-express/config.js:ro"
      ports:
      - "8081:8081"

And my ./config.js

module.exports = {
    mongodb: {
        connectionOptions: {
            ssl: true,
            sslValidate: false
        }
    }
};

These two options should be configurable by setting ME_CONFIG_MONGODB_SSL=true and ME_CONFIG_MONGODB_SSLVALIDATE=false, but for some reason only providing a custom config works.

ANovokmet avatar Oct 19 '21 13:10 ANovokmet