Clean all the collections in a mongo database
npm install mongo-clean --save-dev
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
})
MIT