Hi,
I get this error while trying to connect to mongodb-memory-server:
Error:
Too small (243 bytes) mongod binary downloaded from https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian-4.tgz
Here is the complete log:
> [email protected] test /home/user/dev/my-project
> ava
⠴ Autostarting MongoDB instance...
⠦ Called MongoMemoryServer.start() method:
⠧ Called MongoMemoryServer.ensureInstance() method:
⠋ Starting MongoDB instance with following options: {"port":44221,"dbName":"c29f4ff0-5bdb-4754-a869-4d68a96357be","uri":"mongodb://127.0.0.1:44221/c29f4ff0-5bdb-4754-a869-4d68a96357be","storageEngine":"ephemeralForTest","dbPath":"/tmp/mongo-mem-10161t2d42i3UC0oV","tmpDir":{"name":"/tmp/mongo-mem-10161t2d42i3UC0oV"}}
⠹ MongoBinary options: {"downloadDir":"/home/user/dev/my-project/node_modules/.cache/mongodb-memory-server/mongodb-binaries","platform":"linux","arch":"x64","version":"4"}
⠸ Called MongoMemoryServer.ensureInstance() method:
⠧ Downloading:
⠇ random_test › before hook
2 hooks failed
4 unhandled rejections
/home/user/dev/my-project/node_modules/mongodb-memory-server/src/util/MongoBinaryDownload.ts:225
Rejected promise returned by test. Reason:
Error {
message: 'Too small (243 bytes) mongod binary downloaded from https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian-4.tgz',
}
This is the source code I try to run:
import mongoose from 'mongoose';
import MongodbMemoryServer from 'mongodb-memory-server';
// Create mongodb in memory server
const mongod = new MongodbMemoryServer();
// Create connection to mongoose before all tests
export async function before(t) {
const uri = await mongod.getConnectionString();
await mongoose.connect(uri, {
createIndexes: true,
useNewUrlParser: true
});
}
// Disconnect MongoDB and mongoose after all tests are done
export async function after(t) {
mongoose.disconnect();
mongod.stop();
}
Any advice would be helpfull.
Thanks!
Are you behind a proxy ?
Download URL does not exist
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian-4.tgz
Take a look at mongodb repo for avaliable versions under linux https://www.mongodb.org/dl/linux
@Yaty I am not behind proxy. The code above is running perfectly fine on arch linux, but the issue appears on debian buster. I built mongodb from source and it is running fine. I think the issue is somewhat with the download url...
@nodkz I am not exactly sure what should I download from this url.
The issue appears on npm install on the debian buster machine, here is the log:
𝝺 npm i
> [email protected] postinstall /home/user/dev/my-project/node_modules/mongodb-memory-server
> node ./scripts/postinstall.js
mongodb-memory-server: checking MongoDB binaries cache...
failed to download/install MongoDB binaries. The error:
Error: Too small (243 bytes) mongod binary downloaded from https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian-4.0.3.tgz
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 685 packages from 327 contributors and audited 6177 packages in 13.963s
found 1 high severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
From @nodkz comment above, it looks like the linux downloads aren't on the fastdl.mongodb.org site. Instead, they're located at downloads.mongodb.org.
eg: for 3.4 latest, the URL should be http://downloads.mongodb.org/linux/mongodb-linux-x86_64-debian81-v3.4-latest.tgz
To get this working* on Bitbucket pipelines, I setup environmental variables as follows:
MONGOMS_DOWNLOAD_MIRROR="http://downloads.mongodb.org"
MONGOMS_VERSION="v4.0-latest"
Bitbucket pipelines runs on debian 9.2, resulting in the "correct" url: http://downloads.mongodb.org/linux/mongodb-linux-x86_64-debian92-v4.0-latest.tgz
NOTE: I want to run v 3.4, however there are no debian downloads for 3.4-latest, so I've gone with 4.0 for now. Not an ideal situation, but at least I have some sense of security w/ my tests running now
Maybe worth noting would be to also check if you don't have some older version (which cannot be downloaded) specified in the mongo-memory-server constructor.
binary: {
version: ...
}
https://github.com/nodkz/mongodb-memory-server#available-options
10x all !
It looks like @pdfowler solution should do the trick.
Can't verify anymore because of switch the debian out.
Most helpful comment
From @nodkz comment above, it looks like the linux downloads aren't on the
fastdl.mongodb.orgsite. Instead, they're located atdownloads.mongodb.org.eg: for 3.4 latest, the URL should be http://downloads.mongodb.org/linux/mongodb-linux-x86_64-debian81-v3.4-latest.tgz
To get this working* on Bitbucket pipelines, I setup environmental variables as follows:
Bitbucket pipelines runs on debian 9.2, resulting in the "correct" url:
http://downloads.mongodb.org/linux/mongodb-linux-x86_64-debian92-v4.0-latest.tgzNOTE: I want to run v 3.4, however there are no debian downloads for
3.4-latest, so I've gone with 4.0 for now. Not an ideal situation, but at least I have some sense of security w/ my tests running now