JSPM

mongo-memory

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q24282F
  • License MIT

mongodb in memory for testing or mocking

Package Exports

  • mongo-memory

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mongo-memory) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Mongo Memory

Build Status

Bootstrap programmatically Mongodb for testing or mocking during development.

Works on all platforms which is due to the awesome mongodb-prebuilt package.

Installation

npm install mongo-memory

Usage

const MongoInMemory = require('mongo-memory')

const port = 8000
const dbPath = ".." // Mongodb placed some metadata
const mongoServerInstance = new MongoMemory(port, dbPath)

mongoServerInstance.start().then(server) => {

    mongoServerInstance.getMongouri('myDatabaseName')
    mongoServerInstance.getCollection('coll1')
    mongoServerInstance.getDocument('myDatabaseName', 'coll1', "<id>")
    mongoServerInstance.addDocument('myDatabaseName', 'coll1', { a: 1, b: 2 })
    mongoServerInstance.addDirectoryOfCollections('myDatabaseName', '<path>')

})

mongoServerInstance.stop()

Background

Mongodb storageEngione ephemeralForTest is used.

Credits

Most code was copied from mongo-in-memory

Changes:

  • Don't save metadata in node_modules
  • Don't generate random folders
  • Clean up of metadata must be handled by user
  • 100% Promise API
  • Update mongodb-prebuilt to the newest version
  • Update dependencies and tests
  • Gracefully shutdown Mongodb when execute stop
  • Create recursively databasePath