I am running some integration tests w/ the Node.js Mongodb native driver. Each test involves connecting to a database, verifying that it doesn't already exist (e.g. doesn't have any collections w/ documents), running a test, and then dropping the database. High-level code is as follows:
const runSafeTest = function runSafeTest(test) {
async.waterfall([
connectToMongo,
throwIfDbExists,
instantiateServerConnection,
test
],
function doneWaterfall(err, db) {
db.dropDatabase(function(dbErr) {
if (dbErr) throw dbErr
});
})
};
Every time db.dropDatabase()
gets called it throws the following error:
MongoError: topology was destroyed
Not asking for specific debugging of the above code, but rather just a general question: what does a "topology was destroyed" error in MongoDB mean and what kinds of things could cause it? Have looked through the Mongo docs, the source code, and the other SO questions, but can't find a clear answer on what "topology was destroyed" means and how i might prevent it from manifesting in the testing approach we're using.
Thanks!
On the off-chance anyone ever stumbles across this question, the problem was an errant db.close()
call on the same db reference used later for db.dropDatabase()
. IMO 'topology was destroyed' is an odd error for this (maybe 'socket closed'), but in this case was the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With