I'm trying to use commands such as mongoimport, mongodump and mongorestore to prepare my testing db before running my tests but I'm getting the error "bash: mongoimport: command not found"
My bitbucket-pipelines.yml file looks something like:
image: node:8
pipelines:
branches:
Development:
- step:
name: Test
caches:
- node
services:
- mongo
script:
- mongoimport --uri "testDB" --drop --collection users --file ./seed/users.json
- mongodump --uri "otherDB" --out "/backups"
- mongorestore --uri "testDB" --db testDB "/backups/otherDB"
- npm install
- npm test
definitions:
services:
mongo:
image: mongo
I'm not sure why I don't have access to the mongodb commands, I thought having the service running would allow me to easily perform a dump and restore.
Hi @dervisc,
The reason you can't run these commands is because the build container doesn't have mongo db utilities installed even if the service container does.
Because services run in different containers using different docker images their libraries and bash configuration are not shared.
To fix your problem you will need to make sure the mongodb-org-tools package is installed in your build container. I recommend using the command apt install mongodb-org-tools to install them. This will require some package repository configuration.
This page https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition has a lot of the details for the packages required. If problems are encountered this answer https://askubuntu.com/questions/842592/apt-get-fails-on-16-04-installing-mongodb has details on configuring the packages correctly for newer mongo versions.
You may also wish to build your own docker image that already has the utilities installed so you don't have to download them every time.
Otherwise, just run the commands to install the utilities either through a script file or as raw commands in the bitbucket-pipelines.yml and you should be able to use the tools.
Cheers,
Tom
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.