DEV Community

Rittwick Bhabak
Rittwick Bhabak

Posted on

#7 Dropping a Collection

To drop a collection:
mongoose.connection.collections.mariochars.drop()
note that we're writing mariochars (pluralized) and not mariochar but we've declared the collection as mariochar. This is the way mongodb works.

To drop the collection before every test so that the result of one test do not affect the other test by using beforeEach

const mongoose = require('mongoose');mongoose.Promise = global.Promise 
before(function(done){
    // Connect to mongodb
    ...
})
beforeEach(function(done){
    mongoose.connection.collections.mariochars.drop()
    done()
})
Enter fullscreen mode Exit fullscreen mode

Top comments (0)