Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to perform mongorestore from bitbucket pipelines?

dervisc August 14, 2018

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. 

1 answer

1 vote
Tom Bradshaw
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 16, 2018

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events