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

8

5
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

> [email protected] 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.
Termor answered 6/6, 2020 at 2:17 Comment(0)
D
17

Seems you have the same issue like I have had.

https://github.com/nodkz/mongodb-memory-server/issues/316

Specify binary version in package.json E.g:

"config": {
    "mongodbMemoryServer": {
      "version": "latest"
    }
  },
Decontaminate answered 9/6, 2020 at 16:7 Comment(2)
it doesn't help for me and gives a "failed to download/install MongoDB binaries. The error: TypeError: Invalid Version: latest"Silicious
@Silicious try updating mongodb-memory-server to 6.6.7, and then use this solution (it used to work before, then it broke, and now it's fixed again)Malamute
C
5

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

  "config": {
        "mongodbMemoryServer": {
          "version": "4.4.1"
        }
      }
Cuprous answered 8/10, 2020 at 10:20 Comment(0)
T
4

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"
Tonitonia answered 25/6, 2021 at 5:10 Comment(0)
V
1

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.

Voguish answered 22/9, 2021 at 5:16 Comment(0)
J
0

Try this version [email protected]

Jewell answered 31/8, 2020 at 17:51 Comment(0)
G
0

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

Gera answered 14/6, 2022 at 20:28 Comment(0)
V
0

This problem can occur for many reasons, I think most were already covered in the existing answers, but none solved my case specifically.

For those, like me, that are using Ubuntu 22.04, it may be a version compatibility issue. I was using the npm package @shelf/jest-mongodb at version 2.0.3, which depends on mongodb-memory-server on 7.6.3, which has no compatibility with Ubuntu 22.04 (and probably other newer OSs).

There is a issue tracking this problem on jest-MongoDB, which points to another issue on mongodb-memory-server.

TL;DR

If you use mongodb-memory-server directly, try to update it to the newest version.

If you use some package that depends on it, like jest-mongodb, try to update it to the newest version.

Viviennevivify answered 24/2, 2023 at 17:54 Comment(0)
B
0

If you're using Ubuntu 22.04 or newer, set the MongoDB version to 6.0.3 as a workaround for https://github.com/nodkz/mongodb-memory-server/issues/846

Barn answered 17/1 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.