What is the mongo connection uri in circle ci?

Viewed 32

I'm running mongo on circle ci and it seems like everything is connected fine, however the application hangs and never connects to the DB.

Here's the config.yml

version: 2.1

orbs:
  node: circleci/node@5.0.2
  nx: nrwl/nx@1.5.1

commands:
  bt-setup:
    steps:
      - checkout
      - bt-yarn-install

  bt-mongo:
    steps:
      - run:
          name: MongoDB Install
          command: |
            sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
            echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
            sudo apt-get update
            sudo apt-get install -y mongodb-org-shell
      - setup_remote_docker:
          version: 20.10.14
      - run:
          name: Dockerize Mongo
          command: dockerize -wait tcp://localhost:27017 -timeout 1m
      - run:
          name: Get versions
          command: |
            node -v
            npm -v
            mongo --version
            mongo localhost --eval "db.version()"
      - run:
          name: Connect to DB
          command: mongo --eval "printjson(db.apikeys.count());" localhost

  bt-yarn-install:
    steps:
      - node/install-packages:
          pkg-manager: yarn

jobs:
  test-api:
    docker:
      - image: cimg/node:lts-browsers
      - image: mongo:4.4.14
    environment:
      NX_CLOUD_DISTRIBUTED_EXECUTION: "true"
    steps:
      - bt-setup
      - bt-mongo
      - run:
          name: Run Tests
          command: |
            MONGODB_URI=mongodb://127.0.0.1:27017/localhost IS_CI_TEST=true yarn test:api --run-in-band
      - bt-nx-stop

workflows:
  build:
    jobs:
      - test-api

And the output:

$ node -v
v16.16.0

$ npm -v
8.11.0

$ mongo --version
MongoDB shell version v4.0.28
git version: af1a9dc12adcfa83cc19571cb3faba26eeddac92
OpenSSL version: OpenSSL 1.1.1f  31 Mar 2020
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1804
    distarch: x86_64
    target_arch: x86_64

$ mongo localhost --eval "db.version()"
MongoDB shell version v4.0.28
connecting to: mongodb://127.0.0.1:27017/localhost?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("ceab1ceb-c061-4be2-bc34-ef72f67331d5") }
MongoDB server version: 4.4.14
WARNING: shell and server versions do not match
4.4.14

any ideas what's going on? Is my connection string url correct?

MONGODB_URI=mongodb://127.0.0.1:27017/localhost
0 Answers
Related