我们在https://github.com/keystonejs/keystone已经在我们的e2e测试服务器中执行了以下操作,暂时没有问题,在e2e启动之前删除数据库:
mongoose.connect(mongoUri,function(err){
if (!err) {
mongoose.connection.db.dropDatabase(function (err) {
mongoose.connection.close(function(err) {
done(err);
})
});
} else {
done(err);
}
});
但是最近(Mongoose 4.5.9)我们现在在启动时遇到以下错误。有任何想法吗?我们是否需要根据最近的更新来调整上面的drop db逻辑?
10:00:20:493 e2e: dropping test database
Mongoose model 'index-single-done' event fired on 'Boolean' for index:
{ key: 1 }
With error:
topology was destroyed MongoError: topology was destroyed
at Server.insert (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb-core\lib\topologies\server.js:1312:49)
at Server.insert (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\server.js:351:17)
at C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\db.js:1018:21
at handleCallback (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\utils.js:96:12)
at C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\db.js:1697:20
at handleCallback (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\utils.js:96:12)
at C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\db.js:306:20
at commandCallback (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb-core\lib\topologies\server.js:1182:20)
at Callbacks.flush (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb-core\lib\topologies\server.js:88:7)
at Server.destroy (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb-core\lib\topologies\server.js:1075:41)
at Server.close (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\server.js:398:17)
at Db.close (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\db.js:357:19)
at NativeConnection.doClose (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongoose\lib\drivers\node-mongodb-native\connection.js:233:11)
at NativeConnection.Connection._close (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongoose\lib\connection.js:570:12)
at C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongoose\lib\connection.js:541:11
at lib$es6$promise$$internal$$initializePromise (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\es6-promise\dist\es6-promise.js:409:9)
Mongoose model 'index' event fired on 'Boolean' with error:
topology was destroyed MongoError: topology was destroyed
at Server.insert (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb-core\lib\topologies\server.js:1312:49)
at Server.insert (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\server.js:351:17)
at C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\db.js:1018:21
at handleCallback (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\utils.js:96:12)
at C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\db.js:1697:20
at handleCallback (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\utils.js:96:12)
at C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\db.js:306:20
at commandCallback (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb-core\lib\topologies\server.js:1182:20)
at Callbacks.flush (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb-core\lib\topologies\server.js:88:7)
at Server.destroy (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb-core\lib\topologies\server.js:1075:41)
at Server.close (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\server.js:398:17)
at Db.close (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb\lib\db.js:357:19)
at NativeConnection.doClose (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongoose\lib\drivers\node-mongodb-native\connection.js:233:11)
at NativeConnection.Connection._close (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongoose\lib\connection.js:570:12)
at C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongoose\lib\connection.js:541:11
at lib$es6$promise$$internal$$initializePromise (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\es6-promise\dist\es6-promise.js:409:9)
Mongoose model 'index-single-done' event fired on 'CloudinaryImage' for index:
{ key: 1 }
With error:
topology was destroyed MongoError: topology was destroyed
at Server.insert (C:\Users\Carlos\git\prs\keystonejs\master\node_modules\keystone\node_modules\mongodb-core\lib\topologies\server.js:1312:49)
...
答案 0 :(得分:1)
原来这是一个逻辑错误!棘手的逻辑是初始化mongoose模式模型,然后删除数据库,然后关闭数据库,然后使用数据库进行正常操作。无论出于何种原因,这种方法工作了很长时间没有任何错误。在遇到导致上述错误的同步问题之前,性能可能会提高一些。