咕噜任务砸猫鼬数据库 [英] Grunt task to drop mongoose database
本文介绍了咕噜任务砸猫鼬数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建一个任务咕噜猫鼬通过删除MongoDB数据库。该连接悬挂,我必须强制退出,这是不实际删除数据库或输出错误。
VAR DB =要求('./ DB /模式');grunt.registerTask('砸','删除数据库',函数(){
//异步模式
VAR完成= this.async(); db.mongoose.connection.db.dropDatabase(功能(错误){
如果(ERR){
的console.log(ERR);
}其他{
的console.log('成功删除数据库');
}
db.mongoose.connection.close(完成);
});});
输出
$咕噜下降
运行滴的任务
已成功连接到:MongoDB中://本地主机/测试
^ C
解决方案
终于找到了解决我这里的问题:的 https://groups.google.com/forum/?fromgroups=#!topic/mongoose-orm/Cck_VND80r8 只好来包装connection.on 家居p>
grunt.registerTask('降','删除数据库',函数(){
//异步模式
VAR完成= this.async();db.mongoose.connection.on(开放,函数(){
db.mongoose.connection.db.dropDatabase(功能(错误){
如果(ERR){
的console.log(ERR);
}其他{
的console.log('成功删除数据库');
}
db.mongoose.connection.close(完成);
});
});
});
I'm trying to create a grunt task to drop a mongodb database through mongoose. The connection is hanging and I have to force quit and it is not actually dropping the database or outputting an error.
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);
});
});
Output
$ grunt drop
Running "drop" task
Successfully connected to: mongodb://localhost/test
^C
解决方案
Finally found the solution to my problems here: https://groups.google.com/forum/?fromgroups=#!topic/mongoose-orm/Cck_VND80r8 Had to wrap everything in connection.on
grunt.registerTask('drop', 'drop the database', function() {
// async mode
var done = this.async();
db.mongoose.connection.on('open', function () {
db.mongoose.connection.db.dropDatabase(function(err) {
if(err) {
console.log(err);
} else {
console.log('Successfully dropped db');
}
db.mongoose.connection.close(done);
});
});
});
这篇关于咕噜任务砸猫鼬数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文