mongodb-memory-server | If you run tests | Testing library

 by   nodkz TypeScript Version: 9.3.0-beta.1 License: MIT

kandi X-RAY | mongodb-memory-server Summary

kandi X-RAY | mongodb-memory-server Summary

mongodb-memory-server is a TypeScript library typically used in Testing, Nodejs applications. mongodb-memory-server has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

Spinning up mongod in memory for fast tests. If you run tests in parallel this lib helps to spin up dedicated mongodb servers for every test file in MacOS, *nix, Windows or CI environments (in most cases with zero-config).

            kandi-support Support

              mongodb-memory-server has a medium active ecosystem.
              It has 2225 star(s) with 165 fork(s). There are 15 watchers for this library.
              There were 8 major release(s) in the last 6 months.
              There are 19 open issues and 423 have been closed. On average issues are closed in 130 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of mongodb-memory-server is 9.3.0-beta.1

            kandi-Quality Quality

              mongodb-memory-server has no bugs reported.

            kandi-Security Security

              mongodb-memory-server has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              mongodb-memory-server is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              mongodb-memory-server releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of mongodb-memory-server
            Get all kandi verified functions for this library.

            mongodb-memory-server Key Features

            No Key Features are available at this moment for mongodb-memory-server.

            mongodb-memory-server Examples and Code Snippets

            How to get Jest working with an in-memory MongoDB server?
            JavaScriptdot img1Lines of Code : 54dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            yarn global add jest @shelf/jest-mongodb mongodb-memory-server
            yarn        add jest @shelf/jest-mongodb mongodb-memory-server
            yarn add v1.21.1
            info No lockfile found.
            [1/4] Resolving packag

            Community Discussions


            Unable to use promise returned by Jest beforeAll
            Asked 2021-May-25 at 09:19

            I am trying to write unit tests for my mongodb queries using mongodb-memory-server, mongodb and Jest. I am trying to setup the db from beforeAll and hoping to use the promises returned into my test.

            Here is my code which I have developed using the Jest documentation provided in their setup and teardown section:




            Answered 2021-May-25 at 08:57

            You need to assign the return value of initdb to something:



            Error with jest config: "Preset @shelf/jest-mongodb not found."
            Asked 2021-Apr-05 at 22:24

            i have a project that uses jest, i can run jest with npm test and it works if i dont set a preset.

            I need the preset @shelf/jest-mongodb, and i get the error that is in the title of this post.

            Here is my jest.config.js:



            Answered 2021-Apr-05 at 22:24


            Error: Status Code is 403 (MongoDB's 404) This means that the requested version-platform combination dosnt exist
            Asked 2020-Oct-08 at 10:29
            beforeAll(async () => {
                mongo = new MongoMemoryServer();
                const mongoURI = await mongo.getConnectionString();
                await mongoose.connect(mongoURI, {
                    useNewUrlParser: true,
                    useUnifiedTopology: true


            Answered 2020-Jun-09 at 16:07

            Seems you have the same issue like I have had.


            Specify binary version in package.json E.g:



            mongo-db-memory-server with Jest
            Asked 2020-Sep-05 at 19:04

            I am trying to write a sample application for POC of mongodb-memory-server but unfortunately its not working. I checked several links and blogs but seems like code working for all is not working for me. Jest test times out even after increasing timeout to 1 min. getConnectionString or getUrl both times out. I suspect this mongodb-memory-server never starts.

            Following is DB Handler for tests

            I am using Windows 10



            Answered 2020-Sep-05 at 19:04

            Check this issue:

            I was having the same problem today.I solved this by replacing mongod.exe from node_modules/.cashe/mongodb-memory-server/mongodb-binaries/latest for the older version. But I think the right way would be to state older version in the package.json:



            Sending Mapquest/Google API Key In Jest Using ChaiHttp
            Asked 2020-Jun-05 at 15:38

            Context: I have a back-end API application that I'm working on where I have series of tests for the API. The project is here: This project has a series of tests that I've been developing. As far as the test tooling, I'm using ChaiHttp, Jest, and mongodb-memory-server. I should probably note that this is my first real JavaScript project and I'm learning the test tooling as I go.

            Problem: All of those tests were working great ... up until I added some geocoder functionality. Specifically, I added the node-geocoder package.

            Error Condition:

            I get the following error on some of my routes when the tests are run:



            Answered 2020-Jun-05 at 15:38

            Okay, I figured it out. I was on the right track with my process.env findings. The solution was as such:

            In package.json I had to add this:



            Create in-memory database using mongodb-memory-server and mongoose
            Asked 2020-May-14 at 07:31

            I want to create a in-memory database using mongodb-memory-server and mongoose. Can anyone show the correct way to do it.



            Answered 2020-May-14 at 07:31

            Read the documentation here and came accross the following solution.



            Nest can't resolve dependencies of the UsersService
            Asked 2020-Mar-23 at 14:27

            I am trying to set up Authorisation in NestJs using Mongoose via a User Service. I'm getting the following errors when trying to Unit Test:

            I understand that the UserModel is injected into the UsersService and needs to be resolved when using the UsersModule but I can't work out how to do this when creating the TestingModule. Please can someone shed some light on this for me?

            Code is below, thanks:

            USER MODULE



            Answered 2020-Mar-22 at 15:19

            In unit tests, you should mock all necessary dependencies for AuthService. It's not e2e test, you shouldn't initialize MongooseModule here. Your beforeEach should look like that:



            Docker fails on npm install
            Asked 2020-Feb-10 at 12:43

            I'm new to Docker, and I've wanted try Dockerizing my node app.

            I've tried following the directions on, but I've been getting errors on npm install.

            Here is my Dockerfile:



            Answered 2020-Feb-10 at 12:43

            I used to get this error due to low or intermittent internet bandwidth.



            How to get Jest working with an in-memory MongoDB server?
            Asked 2019-Dec-24 at 05:40

            I am making my first tentative steps into modern JS development, and to do so, I am writing an app, with the intention of running it on Mongo Stitch. I am trying to stick to TDD-ish development, partly because it is good practice, and partly because it is much easier to run things locally than in the Stitch environment.

            I have a working Docker/Alpine environment, and it runs unit tests against Stitch functions fine using Jest. However, I am now writing functions where the conditionals/logic are in Mongo, so unit tests are not enough to protect against regressions.

            My original plan was to spin up a MongoDB 4.0 instance in Docker Compose, and then work out how to connect to it in Jest. However, the Jest docs have pointed me to an in-memory MongoDB, which sounds pretty good. Unfortunately it seems non-trivial to set up, and I am bumping into a number of errors.

            I am using Yarn to pull dependencies. Since this appears to compile some binaries, I wondered if my being on Alpine was complicating things (BusyBox builds tend to be a bit trickier). I have therefore swapped to Ubuntu. My Dockerfile is pretty simple:



            Answered 2019-Dec-24 at 05:40

            The issue was solved by @OTZ in the comments; I am expanding on the solution here for reference.

            The original Yarn install command in the Dockerfile was thus:



            How can I catch the mongodb error to pass the test in jest?
            Asked 2019-Dec-07 at 11:50

            I create a user schema using mongoose.




            Answered 2019-Dec-07 at 11:50

            According to jest/rejects, I used rejects to pass my test:


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install mongodb-memory-server

            This tool provides three packages for different purposes:. Choose any package, because they are the same. They differ only in the default configuration, which you may override (see section Available options).
            With auto-download mongod binary on npm install (mongodb-memory-server, mongodb-memory-server-global-*)
            Without auto-download on npm install (mongodb-memory-server-core)


            Contributing Guidelines are setup in CONTRIBUTING.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • npm

            npm i mongodb-memory-server

          • CLONE
          • HTTPS


          • CLI

            gh repo clone nodkz/mongodb-memory-server

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link