DEV Community

loading...

#7 Dropping a Collection

rittwickbhabak profile image Rittwick Bhabak ・1 min read

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

Discussion

pic
Editor guide