Socket
Socket
Sign inDemoInstall

mongodb-memory-server-core

Package Overview
Dependencies
183
Maintainers
2
Versions
261
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mongodb-memory-server-core

MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.


Version published
Weekly downloads
589K
increased by12.4%
Maintainers
2
Install size
16.0 MB
Created
Weekly downloads
 

Package description

What is mongodb-memory-server-core?

The mongodb-memory-server-core package provides an in-memory MongoDB server for testing purposes. It allows developers to spin up a MongoDB server instance that runs entirely in memory, making it ideal for unit tests and integration tests where a real MongoDB server would be overkill or too slow.

What are mongodb-memory-server-core's main functionalities?

Start an In-Memory MongoDB Server

This feature allows you to start an in-memory MongoDB server instance. The code sample demonstrates how to create a new MongoMemoryServer instance and retrieve its URI.

const { MongoMemoryServer } = require('mongodb-memory-server-core');
(async () => {
  const mongod = new MongoMemoryServer();
  const uri = await mongod.getUri();
  console.log(`MongoDB Server started at ${uri}`);
})();

Stop the In-Memory MongoDB Server

This feature allows you to stop the in-memory MongoDB server instance. The code sample demonstrates how to start and then stop the MongoMemoryServer instance.

const { MongoMemoryServer } = require('mongodb-memory-server-core');
(async () => {
  const mongod = new MongoMemoryServer();
  await mongod.start();
  console.log('MongoDB Server started');
  await mongod.stop();
  console.log('MongoDB Server stopped');
})();

Use with Mongoose

This feature allows you to use the in-memory MongoDB server with Mongoose. The code sample demonstrates how to connect Mongoose to the in-memory MongoDB server, perform database operations, and then disconnect and stop the server.

const mongoose = require('mongoose');
const { MongoMemoryServer } = require('mongodb-memory-server-core');
(async () => {
  const mongod = new MongoMemoryServer();
  const uri = await mongod.getUri();
  await mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true });
  console.log('Mongoose connected to in-memory MongoDB');
  // Perform database operations
  await mongoose.disconnect();
  await mongod.stop();
})();

Other packages similar to mongodb-memory-server-core

Changelog

Source

8.11.3 (2023-01-19)

Fixes

  • MongoBinaryDownloadUrl: support ubuntu 22.04 ^6.0.4 (6598792), closes #732

Readme

Source

mongodb-memory-server-core

Node.js CI NPM version Downloads stat Commitizen friendly TypeScript compatible codecov.io Backers on Open Collective Sponsors on Open Collective mongodb-memory-server-core

Core package which contains main code. Used in all other packages.

Full README with available options and examples

Keywords

FAQs

Last updated on 19 Jan 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc