I am doing mocha testing. I have to connect to MongoDB in before
function and I need to remove the documents in the collection in after function.
before("authenticate user", async () => {
mongoose.connect('mongodb://localhost:27017/mo-identity')
db = mongoose.connection;
db.once('open', function() {
console.log('We are connected to test `enter code here`database!')
})
.on('error', ()=>{console.error.bind(console, 'connection error')})
})
after(()=>{
db.User.drop()
})
Above is my code.
user
is a collection. While executing this code I am getting this error TypeError: Cannot read property 'drop' of undefined
. Help me out this error