2.0.0 • Published 6 years ago

mongo-clean v2.0.0

Weekly downloads
648
License
MIT
Repository
github
Last release
6 years ago

mongo-clean

Build
Status

Clean all the collections in a mongo database

Install

npm install mongo-clean --save-dev

Usage

Pass the database handler to clean.

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

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

Clean the db excluding a list of collections

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

MongoClient.connect(url, { w: 1 }, function (err, client) {
  clean(client.db('mongocleantest'), {exclude: ['dummy1', 'dummy2']}, function (err) {
    // Delete all the collections in the db except dummy1 and dummy2
  })
})

Removing all elements instead of dropping the collections:

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

MongoClient.connect(url, { w: 1 }, function (err, client) {
  clean(client.db('mongocleantest'), { action: 'remove' }, function (err) {
    // automatically removes all the data from all the collections in the db
  })
})

Promises and async await are supported as well.

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

MongoClient.connect(url, { w: 1 }, function (err, client) {
  clean(client.db('mongocleantest'))
    .then(console.log)
    .catch(console.log)
})

License

MIT

2.0.0

6 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.1.0

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago