Comments (7)
Nice catch ! Here is a fix #106 using the cwd
option
from mongodb-memory-server.
@guillaumervls Nice fix ;)
from mongodb-memory-server.
@akateiva The binaries are downloaded in the same directory in the post_install script and at runtime, both of them in the directory /node_modules/.cache/mongodb-memory-server/mongodb-binaries, they both pass through the getPath method of the MongoBinary class.
When the download is done, a folder corresponding to the version of mongodb used is created in that directory, in your case that folder is /latest/mongod containing the binary.
So if you downloaded the binary in the post install script and you then use the module it should not download it again since the binary is already present in the right directory.
In which context are you using the module ? In different CI jobs ?
On your trace I cannot see the new download of the binary.
from mongodb-memory-server.
@AJRdev I'm using the module for tests in a CI job.
In my trace I show the result of path.resolve(findCacheDir({ name: 'mongodb-memory-server' }), 'mongodb-binaries');
, which is taken from MongoBinary.js line 33 . You can see that the directory to which the binaries were downloaded during post-install is the .cache folder under mongodb-memory-server package, while at run-time the binary path is downloaded to the root package's .cache folder.
Anyway, I added const mongod = new mongoms.MongoMemoryServer({debug: true});
to the trace so you can see the download dir.
docker run -it --rm node:11 /bin/bash
root@3971eceabc15:/# npm init --yes
Wrote to /package.json:
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
root@3971eceabc15:/# npm install --save mongodb mongodb-memory-server
> [email protected] postinstall /node_modules/mongodb-memory-server
> node ./postinstall.js
mongodb-memory-server: checking MongoDB binaries cache...
mongodb-memory-server: binary path is /node_modules/mongodb-memory-server/node_modules/.cache/mongodb-memory-server/mongodb-binaries/latest/mongod
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN @1.0.0 No description
npm WARN @1.0.0 No repository field.
+ [email protected]
+ [email protected]
added 90 packages from 52 contributors and audited 177 packages in 33.606s
found 0 vulnerabilities
root@3971eceabc15:/# node
> const mongoms = require('mongodb-memory-server');
undefined
> const mongod = new mongoms.MongoMemoryServer({debug: true});
Autostarting MongoDB instance...
undefined
> Mongo[33809] Starting MongoDB instance with following options: {"port":33809,"dbName":"25fe9f79-3061-43e0-931c-73e502341f3b","uri":"mongodb://127.0.0.1:33809/25fe9f79-3061-43e0-931c-73e502341f3b","storageEngine":"ephemeralForTest","dbPath":"/tmp/mongo-mem-42KwwXQYlN1Sfm"} +0ms
Mongo[33809] MongoBinary options: {"downloadDir":"/node_modules/.cache/mongodb-memory-server/mongodb-binaries","platform":"linux","arch":"x64","version":"latest"} +7ms
Mongo[33809] Downloading: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-latest.tgz +38ms
Downloading MongoDB latest: 53.7 % (44.7mb / 83.3mb)
(To exit, press ^C again or type .exit)
> Downloading MongoDB latest: 69 % (57.5mb / 83.3mb)
from mongodb-memory-server.
@akateiva Oh my bad, I misread the two paths..
Yes so there is a real problem that we didn't saw by running our CI jobs on the project where the post_install script path and the runtime path for the binary download were the same because the post_install script is at the root level of the project.
In your case and for everyone installing this module, the post_install script is at the root of the mongodb-memory-server npm package in the node_module directory not a the root of the project..
So this line :
path.resolve(findCacheDir({ name: 'mongodb-memory-server' }), 'mongodb-binaries'))
is searching for the binary in the node_modules directory of the npm package (/node_modules/mongodb-memory-server/node_modules/.cache/mongodb-memory-server/) in the post_install script and not at the root of the project like at runtime (/node_modules/.cache/mongodb-memory-server/).
The is quite an issue, because I can't see how we could detect in the post_install script that we should download the binary in the node_modules of the project and not the node_modules of the package itself, we didn't had this problem before because the default path was :
path.resolve(os.homedir(), '.mongodb-binaries');
@nodkz Any thoughts on this ?
from mongodb-memory-server.
Need to fix somehow. 😈
@guillaumervls have you bandwidth for taking care about this problem?
Related: #99
from mongodb-memory-server.
🎉 This issue has been resolved in version 2.7.2 🎉
The release is available on:
Your semantic-release bot 📦🚀
from mongodb-memory-server.
Related Issues (20)
- Enabling debug mode through package.json does not work HOT 3
- Randomizing db names for each test
- GridFS streams not working correctly HOT 4
- Jest + mongodb-memory-server + mongoose - Calling 'find' hangs indefinitely HOT 2
- Invalid version reported for version strings ending in -latest HOT 2
- Ubuntu >= 22.04 is unsupported when using MongoDB >= 6.0.4 HOT 7
- _startUpInstance threw a Error: TypeError: (intermediate value).finally is not a function HOT 3
- Mongod instance closed with code "127" HOT 7
- Case: InMemory DB refuses to update after Making changes to model HOT 7
- Library is missing or cannot be opened: "libcrypto.so.1.1" HOT 2
- 9.1.8 not working out of the box for node:20 docker (LTS images) HOT 5
- ReplicaSet - emulate replication lag HOT 1
- Issue downloading mongo binaries with Nexus set as MONGOMS_DOWNLOAD_MIRROR HOT 8
- Error when trying to run tests HOT 1
- Instance failed to start because a library is missing or cannot be opened: "libcrypto.so.1.1" HOT 8
- Requested Version "6.0.14" is not available for "Debian 12"! Available Versions: ">=7.0.3" HOT 1
- Mongod sometimes fails to start due to ETXTBSY HOT 10
- The download of the mongodb binary is corrupted when using a hoisted dependency in a monorepo HOT 4
- How to initialize data/collections/indexes on startup? HOT 1
- Fix Documentation path because of repository transfer HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongodb-memory-server.