可能导致“拓扑被破坏"的原因是什么?使用node.js mongodb本机调用db.destroyDatabase时发生错误? [英] What could cause a "topology was destroyed" error when calling db.destroyDatabase with node.js mongodb native?

查看:161
本文介绍了可能导致“拓扑被破坏"的原因是什么?使用node.js mongodb本机调用db.destroyDatabase时发生错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一些带有Node.js Mongodb本机驱动程序的集成测试.每个测试都涉及连接到数据库,验证该数据库尚不存在(例如,不包含文档的任何集合),运行测试然后删除数据库.高级代码如下:

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
    });
  })
};

每次调用db.dropDatabase()时,都会引发以下错误:

Every time db.dropDatabase() gets called it throws the following error:

MongoError: topology was destroyed

不是要求对上面的代码进行特定的调试,而只是要求一个一般性问题:MongoDB中的拓扑已被破坏"错误是什么意思,什么原因可能导致它?浏览了Mongo文档,源代码和其他SO问题,但找不到拓扑被破坏"的含义以及如何防止其在我们使用的测试方法中体现的明确答案.

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.

谢谢!

推荐答案

在偶然的情况下,任何人偶然发现此问题时,问题是对随后用于db.dropDatabase()的同一个数据库引用的错误db.close()调用.对此,IMO"拓扑已被破坏"是一个奇怪的错误(也许是"插座关闭"),但在这种情况下是问题所在.

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.

这篇关于可能导致“拓扑被破坏"的原因是什么?使用node.js mongodb本机调用db.destroyDatabase时发生错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆