Skip to content

systemic-mongodb 5.0.6

Install from the command line:
Learn more about npm packages
$ npm install @infinitaslearning/systemic-mongodb@5.0.6
Install via package.json:
"@infinitaslearning/systemic-mongodb": "5.0.6"

About this version

systemic-mongodb

A typescript systemic mongodb component.

Usage

import system from "systemic";
import initMongo from "@infinitaslearning/systemic-mongodb";

system()
  .configure({
    mongodb: {
      uri: "mongodb://127.0.0.1/example",
      options: {
        server: {
          poolSize: 5,
        },
      },
      showConnectionString: false,
    },
  })
  .add("logger", console)
  .add("mongodb", initMongo())
  .dependsOn("config", "logger")
  .start((err, components) => {
    // Do stuff with components.mongodb
  });

Parameters

  • uri Use mongodb:// connection string
  • showConnectionString Show connection string on logs, false by default
  • options Options passed to MongoClient

When migrating from One Beyond systemic-mongodb

The @infinitaslearning/systemic-mongodb package is based on the One Beyond systemic-mongodb package, but is written in TypeScript. It has the following key differences:

  • config expects the connection string in a uri property, instead of url
  • when using Javascript with commonjs, the component needs to be imported as
const initMongo = require("@infinitaslearning/systemic-mongodb").default;

or

const { initMongo } = require("@infinitaslearning/systemic-mongodb");

Mocks

This package includes a mock component, that uses mongodb-memory-server.

import { initMongoMock } from "@infinitaslearning/systemic-mongodb";
import system from "..";

system.set("mongodb", initMongoMock());

The mock accepts the same options as the normal component. The only difference is that is spins up and connects to an in-memory mongo server, instead of connecting to the mongo server at the given uri. It is recommended to ensure that the required in-memory server version is available on your machine/build server by using the following global test setup:

import { prepareMockServer } from "@infinitaslearning/systemic-mongodb";

export default function globalSetup() {
  // pass in the required mongo database version (uses latest when omitted)
  return prepareMockServer("4.4.22");
}

Details


Assets

  • systemic-mongodb-5.0.6.tgz

Download activity

  • Total downloads 2,687
  • Last 30 days 1,249
  • Last week 32
  • Today 0