我正在尝试创建一个 grunt 任务以通过 mongoose 删除 mongodb 数据库。连接挂起,我必须强制退出,它实际上并没有删除数据库或输出错误。
var db = require('./db/schema');
grunt.registerTask('drop', 'drop the database', function() {
// async mode
var done = this.async();
db.mongoose.connection.db.dropDatabase(function(err) {
if(err) {
console.log(err);
} else {
console.log('Successfully dropped db');
}
db.mongoose.connection.close(done);
});
});
输出
$ grunt drop
Running "drop" task
Successfully connected to: mongodb://localhost/test
^C