/bin/bash: mongo: command not found

mongo

#1

I added this to my circleci config file: - image: circleci/mongo:3.4.4

to be able to run a command with mongo via shell, but I get:

#!/bin/bash -eo pipefail

mongo NAME --eval 'db.collection.drop()'

/bin/bash: mongo: command not found

Exited with code 127

How can I use mongo shell and also mongorestore to drop a collection and to import a bson file?

Thank you.


#2

nobody, really?

I also tried to use ssh to search “mongo” and “mongorestore” binaries without success.


#3

please, I really need this.
How can I init my test db for integration tests if you cannot use official mongo’s softwares?


#4

I’m having a same problem. Would like to use mongorestore to populate my database with data before tests. Is the only solution to use machine build instead of docker? Or is there some special way I should define the required docker images? My config is following:

docker:
  - image: circleci/python:3.6.1
  - image: circleci/mongo:3.5.6

#5

All of your commands will run in the first container that is listed this is typically not the database container. This means that the mongo cli is likely not installed.


#6

To add on to Lev’s post, the first container listed in a job is the “primary container”. Commands used in any steps for that job will all be run within the primary container. In the following example:

docker:
  - image: circleci/python:3.6.1
  - image: circleci/mongo:3.5.6
steps:
  - checkout
  - run: echo "Hello World"
  - run: mongo --version

circleci/python:3.6.1 is the primary image. This means that the commands that appear in “steps” which are echo and mongo both run from the primary image.

Including the circleci/mongo:3.5.6 image means that CircleCI will run MongoDB in an additional container with the DB service being available via port 27017 (or whatever port you want to use) in the primary container.

The mongo command, from the MongoDB CLI, and anything else you want to use still needs to be installed in the primary container. This can be done on the fly during your CI build (by writing the commands to install them in your CircleCI config) or by using a custom Docker image.


#7

Hi, thank you for the explanation.

You said

This can be done on the fly during your CI build (by writing the commands to install them in your CircleCI config) or by using a custom Docker image.

But the question is: how…?
Can we use apt-get to install mongodb or are there some limitations?


#8

You have root access to the container so you can install any software you like using apt.

Let me know if you run into any issues with that.


#9

I’m trying to install mongodb shell with this script:

echo "mongodb install script is running"
echo "adding a new apt-key"
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo “deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/testing multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
echo "updating apt"
sudo apt-get update
echo "installing mongodb"
sudo apt-get install -y mongodb-org-shell
echo “mongodb install script comleted”

but I got this log:

mongodb install script is running
adding a new apt-key
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.FYUe6T9zT8 --no-auto-check-trustdb --trust-model always --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-security-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
gpg: requesting key A15703C6 from hkp server keyserver.ubuntu.com
gpg: key A15703C6: public key "MongoDB 3.4 Release Signing Key <packaging@mongodb.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/testing multiverse
updating apt


0% [Working]Ign http://deb.debian.org jessie InRelease

Get:1 http://deb.debian.org jessie-updates InRelease [145 kB]

Ign http://repo.mongodb.org xenial/mongodb-org/testing InRelease

Get:2 http://deb.debian.org jessie Release.gpg [2373 B]

Get:3 http://deb.debian.org jessie Release [148 kB]

Get:4 http://repo.mongodb.org xenial/mongodb-org/testing Release.gpg [801 B]

Get:5 http://repo.mongodb.org xenial/mongodb-org/testing Release [5385 B]

Get:6 http://deb.debian.org jessie-updates/main amd64 Packages [23.1 kB]

Ign http://repo.mongodb.org xenial/mongodb-org/testing Release

Get:7 http://deb.debian.org jessie/main amd64 Packages [9063 kB]

Get:8 http://security.debian.org jessie/updates InRelease [63.1 kB]

Get:9 http://repo.mongodb.org xenial/mongodb-org/testing/multiverse amd64 Packages [25.2 kB]

Get:10 http://security.debian.org jessie/updates/main amd64 Packages [547 kB]

100% [7 Packages 9065 kB]100% [7 Packages 9063 kB]Fetched 10.0 MB in 1s (9467 kB/s)

Reading package lists... 1%
Reading package lists... Done

W: GPG error: http://repo.mongodb.org xenial/mongodb-org/testing Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 58712A2291FA4AD5
W: Size of file /var/lib/apt/lists/deb.debian.org_debian_dists_jessie_main_binary-amd64_Packages.gz is not what the server reported 9063195 9065020
installing mongodb

Reading package lists... 0%
Reading package lists... 1%
Reading package lists... Done


Building dependency tree       


Reading state information... Done

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mongodb-org-shell : Depends: libssl1.0.0 (>= 1.0.2~beta3) but 1.0.1t-1+deb8u6 is to be installed
E: Unable to correct problems, you have held broken packages.
mongodb install script comleted

With this error at the end:

The following packages have unmet dependencies:
mongodb-org-shell : Depends: libssl1.0.0 (>= 1.0.2~beta3) but 1.0.1t-1+deb8u6 is to be installed
E: Unable to correct problems, you have held broken packages.

#10

You’re going to have a tough time installing xenial packages on trusty because of dependency issues.

Does the mongo client that comes with trusty not work for your use case?


#11

Oh yes, I was using the wrong command from the mongodb installation guide. thank u.

However I’m still having an issue when I’m trying to install ‘sudo apt-get install -y mongodb-org’:

Fetched 66.8 MB in 3s (20.8 MB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 30124 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_3.4.9_amd64.deb ...
Unpacking mongodb-org-shell (3.4.9) ...
Selecting previously unselected package mongodb-org-server.
Preparing to unpack .../mongodb-org-server_3.4.9_amd64.deb ...
Unpacking mongodb-org-server (3.4.9) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_3.4.9_amd64.deb ...
Unpacking mongodb-org-mongos (3.4.9) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_3.4.9_amd64.deb ...
Unpacking mongodb-org-tools (3.4.9) ...
Selecting previously unselected package mongodb-org.
Preparing to unpack .../mongodb-org_3.4.9_amd64.deb ...
Unpacking mongodb-org (3.4.9) ...
Setting up mongodb-org-shell (3.4.9) ...
Setting up mongodb-org-server (3.4.9) ...
Adding system user `mongodb' (UID 107) ...
Adding new user `mongodb' (UID 107) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
Adding group `mongodb' (GID 112) ...
Done.
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Done.
invoke-rc.d: unknown initscript, /etc/init.d/mongod not found.
dpkg: error processing package mongodb-org-server (--configure):
 subprocess installed post-installation script returned error exit status 100
Setting up mongodb-org-mongos (3.4.9) ...
Setting up mongodb-org-tools (3.4.9) ...
dpkg: dependency problems prevent configuration of mongodb-org:
 mongodb-org depends on mongodb-org-server; however:
  Package mongodb-org-server is not configured yet.

dpkg: error processing package mongodb-org (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 mongodb-org-server
 mongodb-org
E: Sub-process /usr/bin/dpkg returned an error code (1)
mongodb install script completed

PS: when Mongodb will work on the first container, will “image: circleci/mongo:latest” be useless?


#12

Fixed by myself using: “echo “deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list”

:slight_smile:

Right now, I don’t know if the db is working, because I cannot run my e2e tests caused by this issue https://discuss.circleci.com/t/update-chrome-to-version-59-or-greater-for-circleci-2-0/16323

However this question is still valid: “when Mongodb will work on the first container, will “image: circleci/mongo:latest” be useless?”


#13

In the setup I mentioned, you won’t be installing the Mongo database in your primary container, just the CLI. The database would be in its own container meaning yes, that line will still be needed.


#14

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.