Search code examples
mongodbtravis-cimongoimport

How to call "mongoimport" from a Node.js child-process on Travis-CI.org?


First question on SO... sorry if this goes wrong.

I'm using Mocha to test a Node.js module. The module uses child_process.exec() to call the mongoimport command... if all goes well it should load some test-data into a MongoDB database.

All tests pass on my laptop (Node 6.9, MongoDB v3.4.1), but things fail when I move to using Travis-CI.org:

{
"killed": false,
"code": 127,
"signal": null,
"cmd": "mongoimport -h localhost:27017 -d test -c test_planets --type json --file \"/tmp/planet.json\" --upsertFields planetName"
}

...because, I guess, it's not finding the mongoimport command?

SO helped point me to this .travis.yml file that seems to work great to get a V3 MongoDB spun-up:

language: node_js
node_js:
  - "6.9"
sudo: false
addons:
  apt:
    sources:
      - mongodb-upstart
      - mongodb-3.0-precise
    packages:
      - mongodb-org-server
      - mongodb-org-shell

before_script:
  - sleep 15

...and I'm happy MongoDB is available (other tests have connected and passed). I need a recent version for all the new upsert stuff.

  • But I've hit a wall about how to run the mongoimport command from a Node.js child process on Travis-CI (new to that as well). Is it even possible?

Any help very much appreciated!

Tim


Solution

  • Just add "mongodb-org-tools" to the packages section of your .travis.yml file. That will make the mongoimport command available.