npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@push.rocks/smartmongo

v2.0.14

Published

A module for creating and managing a local MongoDB instance for testing purposes.

Readme

@push.rocks/smartmongo

create a local mongodb for testing

Install

To start using @push.rocks/smartmongo in your project, you first need to install it via npm. You can do this by running the following command in your terminal:

npm install @push.rocks/smartmongo --save-dev

This will add @push.rocks/smartmongo as a development dependency to your project because it's typically used for testing purposes.

Usage

The @push.rocks/smartmongo package provides a convenient way to spin up a local MongoDB instance, primarily for testing purposes. It's designed to simplify the process of configuring and managing a MongoDB replica set during development or in CI/CD pipelines. Below, we present a comprehensive guide on how to utilize the full feature set of this module, employing ESM syntax and TypeScript.

Setting Up

To get started, you must first import the SmartMongo class from the package. This class is responsible for handling the MongoDB instances.

import { SmartMongo } from '@push.rocks/smartmongo';

Creating and Starting a MongoDB Instance

With SmartMongo, you can easily create and start a MongoDB replica set. You can specify the number of replica instances; however, if not specified, it defaults to 1.

async function setupMongoDB() {
  const smartMongoInstance = await SmartMongo.createAndStart(1); // Number of replicas is optional
  return smartMongoInstance;
}

const myDbInstance = await setupMongoDB();

After invoking createAndStart, an instance of MongoDB is spun up and is ready for use. The createAndStart function returns a SmartMongo instance which can be interacted with for further operations.

Accessing MongoDB Connection Information

After instantiation, you might want to connect your application or test suite to the MongoDB instance. The getMongoDescriptor method facilitates this by providing essential connection details.

const mongoDescriptor = await myDbInstance.getMongoDescriptor();
console.log(mongoDescriptor.mongoDbUrl); // Use this URL to connect with Mongoose or MongoDB clients.

Stopping and Cleaning Up

Once your tests have completed or you're done using the MongoDB instance, it’s crucial to properly stop and clean up the resources. @push.rocks/smartmongo provides two methods for this purpose:

  1. stop(): Stops the MongoDB instance without persisting any data.

    await myDbInstance.stop();
  2. stopAndDumpToDir(dirPath): Stops the MongoDB instance and persists the data to the specified directory. This is useful if you need to examine the data post-test or reuse it in subsequent runs.

    await myDbInstance.stopAndDumpToDir('./path/to/dump');

Advanced Usage

@push.rocks/smartmongo also provides advanced features for dumping the database and configuring MongoDB replica sets. These features can be particularly useful for complex testing scenarios or when specific MongoDB behaviors need to be emulated.

Dumping Data

To dump the MongoDB data for inspection or backup purposes, use the stopAndDumpToDir method. This method optionally takes a function to customize the naming scheme of the dumped files based on the document content.

await myDbInstance.stopAndDumpToDir('./path/to/dump', (doc) => {
  return `customNameBasedOnDoc-${doc._id}.bson`;
});

Using @push.rocks/smartmongo significantly simplifies the process of managing MongoDB instances for local testing environments. It abstracts away the complexity of starting, operating, and tearing down MongoDB replica sets, allowing developers to focus on building and testing their applications.

Conclusion

@push.rocks/smartmongo serves as a powerful tool in a developer's arsenal for efficiently configuring, running, and managing MongoDB instances in testing scenarios. By following the above guide, developers can leverage MongoDB in their projects with minimal setup and gain valuable insights into their applications' data interactions in a controlled and reproducible environment.

License and Legal Information

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at [email protected].

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.