Error: Status Code is 403 (MongoDB's 404) This means that the requested version-platform combination dosnt exist

Viewed 7711
beforeAll(async () => {
    mongo = new MongoMemoryServer();
    const mongoURI = await mongo.getConnectionString();

    await mongoose.connect(mongoURI, {
        useNewUrlParser: true,
        useUnifiedTopology: true
    });
});

For some reason mongodb-memory-server, doesn't work and it seems that it's because it's downloading mongodb for some reason? Wasn't mongodb supposed to be included with the package, what is the package downloading? How do we prevent mongodb-memory-server from downloading everytime I use it? Is there a way to make it work as it's intended?

$ npm run test

> auth@1.0.0 test C:\Users\admin\Desktop\projects\react-node-docker-kubernetes-app-two\auth
> jest --watchAll --no-cache

2020-06-06T03:12:45.207Z MongoMS:MongoMemoryServer Called MongoMemoryServer.ensureInstance() method:
2020-06-06T03:12:45.207Z MongoMS:MongoMemoryServer  - no running instance, call `start()` command
2020-06-06T03:12:45.207Z MongoMS:MongoMemoryServer Called MongoMemoryServer.start() method
2020-06-06T03:12:45.214Z MongoMS:MongoMemoryServer Starting MongoDB instance with following options: {"port":51830,"dbName":"b67a9bfd-d8af-4d7f-85c7-c2fd37832f59","ip":"127.0.0.1","storageEngine":"ephemeralForTest","dbPath":"C:\\Users\\admin\\AppData\\Local\\Temp\\mongo-mem-205304KB93HW36L9ZD","tmpDir":{"name":"C:\\Users\\admin\\AppData\\Local\\Temp\\mongo-mem-205304KB93HW36L9ZD"},"uri":"mongodb://127.0.0.1:51830/b67a9bfd-d8af-4d7f-85c7-c2fd37832f59?"}
2020-06-06T03:12:45.217Z MongoMS:MongoBinary MongoBinary options: {"downloadDir":"C:\\Users\\admin\\Desktop\\projects\\react-node-docker-kubernetes-app-two\\auth\\node_modules\\.cache\\mongodb-memory-server\\mongodb-binaries","platform":"win32","arch":"ia32","version":"4.0.14"}
2020-06-06T03:12:45.233Z MongoMS:MongoBinaryDownloadUrl Using "mongodb-win32-i386-2008plus-ssl-4.0.14.zip" as the Archive String
2020-06-06T03:12:45.233Z MongoMS:MongoBinaryDownloadUrl Using "https://fastdl.mongodb.org" as the mirror
2020-06-06T03:12:45.235Z MongoMS:MongoBinaryDownload Downloading: "https://fastdl.mongodb.org/win32/mongodb-win32-i386-2008plus-ssl-4.0.14.zip"
2020-06-06T03:14:45.508Z MongoMS:MongoMemoryServer Called MongoMemoryServer.stop() method
2020-06-06T03:14:45.508Z MongoMS:MongoMemoryServer Called MongoMemoryServer.ensureInstance() method:
FAIL src/test/__test___/Routes.test.ts
  ● Test suite failed to run

    Error: Status Code is 403 (MongoDB's 404)

    This means that the requested version-platform combination dosnt exist

      at ClientRequest.<anonymous> (node_modules/mongodb-memory-server-core/src/util/MongoBinaryDownload.ts:321:17)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        127.136s
Ran all test suites.
6 Answers

For me, "latest" (as in accepted answer) did not work, the latest current version "4.4.1" worked:

  "config": {
        "mongodbMemoryServer": {
          "version": "4.4.1"
        }
      }

For anyone getting the dreaded

''

Error: Status Code is 403 (MongoDB's 404)

This means that the requested version-platform combination doesn't exist

''

I found an easy fix.

in the package.json file we need to add an "arch" for the mongo memory server config

  "config": {
  "mongodbMemoryServer": {
  "debug": "1",
  "arch": "x64"
   }
  },

the error is occurring because the URL link that mongo memory server is creating to download a binary version of mongo is wrong or inaccessible.

By adding debug we now are able to get a console log of the mongo memory server process and it should correctly download because we changed the arch variable to a one that worked for me. **You might need to change the arch depending on you system.

Without adding the arch I was able to see why it was crashing in the console log here:

  MongoMS:MongoBinaryDownloadUrl Using "mongodb-win32-i386-2008plus-ssl-latest.zip" as the Archive String +0ms
  MongoMS:MongoBinaryDownloadUrl Using "https://fastdl.mongodb.org" as the mirror +1ms
  MongoMS:MongoBinaryDownload Downloading: "https://fastdl.mongodb.org/win32/mongodb-win32-i386-2008plus-ssl-latest.zip" +0ms
  MongoMS:MongoMemoryServer Called MongoMemoryServer.stop() method +2s
  MongoMS:MongoMemoryServer Called MongoMemoryServer.ensureInstance() method: +0ms

If you notice it is trying to download "https://fastdl.mongodb.org/win32/mongodb-win32-i386-2008plus-ssl-latest.zip" - if you visit the link you will notice it is a BROKEN LINK and that is the reason mongo memory server is failing to download.

For some reason mongo memory server was defaulting to the i386 arch, which didn't work in my case because the link was broken / inaccessible when I visited it. *normally a download should start right away when visiting a link like that.

I was able to configure the to the correct arch manually in the package.json file. Once I did that, it started to download mongo binary and ran all my tests no problem. You will even notice a console log of the download and displaying the correct download link.

You can find your system arch by going to the command prompt and typing

WINDOWS

SET Processor

MAC

uname -a

** EDIT **

The reason I was running into this was because I was running a 32 bit version of Node.js and my Windows machine was a 64 bit system. After installing to a 64 bit version of Node.js I no longer have to specify the arch type in Package.json file.

you can find what architecture type your Node.js is by typing in your terminal:

node -p "process.arch"

Status 403 usually means that your ip is restricted from server(for example maybe your country is in sanction list like iran,syria,...). The best solution for this challenge is to change dns to dns of vpns. In linux just type:

sudo nano /etc/resolv.conf

And then type your dns in nameserver place.

Try this version mongodb-memory-server@6.5.1

I found a solution for this problem that worked for me.

I just set writing permissions to the binary file of mongod that is used for mongo-memory and is saved in the .cache path of your computer or in the node_modules folder.

just locale the mongod file and set writing permission to the file with chmod +x mongod

Related