Skip to content

Latest commit

 

History

History
69 lines (51 loc) · 1.4 KB

README.md

File metadata and controls

69 lines (51 loc) · 1.4 KB

mongo-clean

Build Status

Clean all the collections in a mongo database

Install

npm install mongo-clean --save-dev

Usage

Reusing the same client:

var clean = require('./')
var MongoClient = require('mongodb').MongoClient
var url = "mongodb://localhost:27017/mongocleantest"

MongoClient.connect(url, { w: 1 }, function (err, db) {
  clean(db, function () {
    // your db is clean!
  })
})

Creating a new client:

var clean = require('./')
var url = "mongodb://localhost:27017/mongocleantest"

clean(url, function (err, db) {
  // automatically does MongoClient.connect for you
  // your db is clean!
})

Clean the db excluding a list of collections

var clean = require('./')
var MongoClient = require('mongodb').MongoClient
var url = "mongodb://localhost:27017/mongocleantest"

MongoClient.connect(url, { w: 1 }, function (err, db) {
  clean(db, {exclude: ['dummy1', 'dummy2']}, function () {
    // Delete all the collections in the db except dummy1 and dummy2
  })
})
var clean = require('./')
var url = "mongodb://localhost:27017/mongocleantest"

clean(url, {exclude: ['dummy1', 'dummy2']}, function (err, db) {
  // automatically does MongoClient.connect for you
  // Delete all the collections in the db except dummy1 and dummy2
})

License

MIT