我正在做摩卡测试。我必须连接到 MongoDBbefore
函数,我需要在函数之后删除集合中的文档。
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()
})
上面是我的代码。user
是一个集合。执行此代码时我收到此错误TypeError: Cannot read property 'drop' of undefined
。帮我解决这个错误
恐怕你不能像这样放弃收藏:
db.User.drop()
如果你想删除集合那么你应该这样做:mongoose.connection.db.dropCollection('User', function(err, result) {...});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)