mongo-interlude

0.2.1 • Public • Published

Mongo-Interlude

Build Status

Lightweight npm package to provide cleaning operations with mongodb easily.

Core purpose of mongo-interlude is to help developers clean-up models in mongodb after or even before tests, to avoid Errors

For now, can be installed with npm:

$ npm install mongo-interlude

... and for dev dependency:

$ npm install -D mongo-interlude

Usage

For now available clearDb module, which removes all data from all your models. Require mongoose adapter.

// require main module
const mongoInterlude = require('mongo-interlude')
 
// require clearDb function
// notice that clearDb returns Promise
const clearDb = mongoInterlude.clearDb
 
...
// e.g. you have after tests function:
after(async () => {
    await clearDb({ mongoose: yourMongooseAdapter, silent: true })
})
...

Params

  • mongoose - your mongoose adapter
  • silent - off logging
  • whitelist - array of model names, which will stay untouched

Return

clearDb also return Object, which contains Success and Errors Arrays:

...
const result = await clearDb({ mongoose: yourMongooseAdapter })
console.log(result)
/*
success: [...], <- contains names of successfully cleared models
errors: [...] <- contains objects with key of failed model and value of error
*/
...

Package Sidebar

Install

npm i mongo-interlude

Weekly Downloads

1

Version

0.2.1

License

ISC

Last publish

Collaborators

  • goncharovnikita