Skip to content

Commit

Permalink
[playground] circumvent mongodb-download out-of-date URLs
Browse files Browse the repository at this point in the history
[mongodb-prebuilt](https://github.com/winfinit/mongodb-prebuilt) uses
[mongodb-download](https://github.com/mongodb-js/mongodb-download) internally
to download mongodb binaries. Unfortunately, the URLs on
https://fastdl.mongodb.org used for these binaries have changed and
`mongodb-download` doesn't seem up-to-date, cf.
mongodb-js/mongodb-download#36 and
mongodb-js/mongodb-prebuilt#59
To bypass this issue, you can manually specify the download URL by setting the
`MONGODB_DL_URI` environment variable. For instance, you can use
the following command line:
`MONGODB_DL_URI=https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-4.0.13.tgz node playground/server.js --automongo`
or
`MONGODB_DL_URI=https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.13.tgz node playground/server.js --automongo`
  • Loading branch information
Adrien Di Mascio committed Dec 8, 2019
1 parent 0d697a9 commit c0fa1e8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,19 @@ node playground/server.js --defaultDataset my-dataset.csv --reset
If you don't have mongodb installed, you can use the `--automongo` flag from the
command line. It will use
[mongodb-prebuilt](https://github.com/winfinit/mongodb-prebuilt) to download
(the first time) and run mongo `3.6.12` and then listen on the port guessed from
(the first time) and run mongo `4.0.13` and then listen on the port guessed from
the `--dburi` flag.

> [mongodb-prebuilt](https://github.com/winfinit/mongodb-prebuilt) uses
> [mongodb-download](https://github.com/mongodb-js/mongodb-download) internally
> to download mongodb binaries. Unfortunately, the URLs on
> https://fastdl.mongodb.org used for these binaries have changed and
> `mongodb-download` doesn't seem up-to-date, cf.
> https://github.com/mongodb-js/mongodb-download/issues/36 and
> https://github.com/mongodb-js/mongodb-prebuilt/issues/59
> To bypass this issue, you can manually specify the download URL by setting the
> `MONGODB_DL_URI` environment variable. For instance, you can use
> the following command line:
> `MONGODB_DL_URI=https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-4.0.13.tgz node playground/server.js --automongo`
> or
> `MONGODB_DL_URI=https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.13.tgz node playground/server.js --automongo`
19 changes: 18 additions & 1 deletion playground/mongo-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
const tmp = require('tmp');
const { MongodHelper } = require('mongodb-prebuilt');

/**
* `mongodb-download` package uses wrong download URLS for mongo binaries
* (cf. https://github.com/mongodb-js/mongodb-download/issues/36)
* Until the issue is fixed, users can set the `MONGODB_DL_URI` environment
* variable to specify the download URL. In that case, we monkeypatch `mongodb-download`
* to use the user specified URL.
*/
if (process.env.MONGODB_DL_URI !== undefined) {
const url = require('url');
const { MongoDBDownload } = require('mongodb-download');
MongoDBDownload.prototype.getDownloadURI = function() {
return new Promise(function(resolve,) {
resolve(url.parse(process.env.MONGODB_DL_URI));
});
}
}

tmp.setGracefulCleanup(); // required to be able to remove directory correctly

/**
Expand All @@ -18,7 +35,7 @@ function portFromuri(dburi) {
return match[2];
}

async function startMongo({ dburi = 'mongodb://localhost:27017', version = '3.6.12' } = {}) {
async function startMongo({ dburi = 'mongodb://localhost:27017', version = '4.0.13' } = {}) {
const port = portFromuri(dburi);
if (port === null) {
throw new Error(
Expand Down

0 comments on commit c0fa1e8

Please sign in to comment.