github nodkz/mongodb-memory-server v2.4.0

latest releases: v9.2.1-beta.1, v9.2.0, v9.2.0-beta.1...
5 years ago

2.4.0 (2018-09-30)

Features

Replica Set start:

import { MongoMemoryReplSet } from 'mongodb-memory-server';

const replSet = new MongoMemoryReplSet();
await replSet.waitUntilRunning();
const uri = await mongod.getConnectionString();
const port = await mongod.getPort();
const dbPath = await mongod.getDbPath();
const dbName = await mongod.getDbName();

// some code

// stop replica set manually
replSet.stop();
// or it should be stopped automatically when you exit from script

Available options

All options are optional.

const replSet = new MongoMemoryReplSet({
  autoStart, // same as for MongoMemoryServer
  binary: binaryOpts, // same as for MongoMemoryServer
  debug, // same as for MongoMemoryServer
  instanceOpts: [
    {
      args,  // any additional instance specific args
      port,  // port number for the instance
      dbPath, // path to database files for this instance
      storageEngine,  // same storage engine options
    },
    // each entry will result in a MongoMemoryServer
  ],
  // unless otherwise noted below these values will be in common with all instances spawned.
  replSet: {
    name,  // replica set name (default: 'testset')
    auth,  //  enable auth support? (default: false)
    args,  // any args specified here will be combined with any per instance args from `instanceOpts`
    count,  // number of `mongod` processes to start; (default: 1)
    dbName,  // default database for db URI strings. (default: uuid.v4())
    ip,  // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`
    oplogSize,  // size (in MB) for the oplog; (default: 1)
    spawn,  // spawn options when creating the child processes
    storageEngine,  // default storage engine for instance. (Can be overridden per instance)
  }
});

Don't miss a new mongodb-memory-server release

NewReleases is sending notifications on new releases.