Node.js 首次关闭后无法重用节点mongodb本机客户端

Node.js 首次关闭后无法重用节点mongodb本机客户端,node.js,mongodb,Node.js,Mongodb,我试图编写一个在Nodejs上使用Mongo本机客户端的小类,但是当我尝试关闭连接,然后再次打开(使用相同的客户端对象)时,操作失败,表示连接已关闭(但我刚刚打开) 那么发生了什么? 关闭连接后,我尝试打开它 await client.connect(); /* [CONSOLE] the options [servers] is not supported the options [caseTranslate] is not supported the options [dbName] is

我试图编写一个在Nodejs上使用Mongo本机客户端的小类,但是当我尝试关闭连接,然后再次打开(使用相同的客户端对象)时,操作失败,表示连接已关闭(但我刚刚打开)

那么发生了什么? 关闭连接后,我尝试打开它

await client.connect();
/* [CONSOLE]
the options [servers] is not supported
the options [caseTranslate] is not supported
the options [dbName] is not supported
the options [mode] is not supported
the options [tags] is not supported
the options [hedge] is not supported
the options [preference] is not supported
the options [isValid] is not supported
the options [slaveOk] is not supported
the options [equals] is not supported
the options [toJSON] is not supported
*/
然后尝试使用数据库连接

console.log(await client.db.(dbName).collection().findOne({}));
// [CONSOLE]
// MongoError: Topology is closed, please connect
我知道(或认为我知道)或发现的 我知道在应用程序运行时保持连接打开是一个很好的做法,但不是这样

我试图创建一个新的变量来连接每一次,并且每次都有效(但这不是这里的想法)

我在Mongo上找到了一个关于它的条目(似乎同样的问题)

问题?
是否有人找到了解决方法,可能我没有使用必须使用的驱动程序?

看起来这是节点驱动程序中的一个已知问题

您应该能够通过从头开始重新创建客户端对象(而不是尝试重新连接已断开连接的现有客户端)来解决此问题。

可能不是问题(或部分问题)。毕竟,我找到了api并查看了
db
对象的可用选项

db(数据库名,选项)

创建共享当前套接字连接的新Db实例。请注意,新的数据库实例是 在父子关系中与原始实例相关,以便在子实例上正确发出事件 数据库实例。子数据库实例被缓存,因此执行两次
db('db1')
将返回相同的实例。 您可以使用选项
noListener
returnNonCachedInstance
控制这些行为

然后,它可能是解析闭合连接的缓存实例,因此使用db作为

await client.db(dbName, {returnNonCachedInstance : true});
按预期工作,它会向我发送消息,但似乎不会干扰

the options [servers] is not supported
the options [caseTranslate] is not supported
the options [dbName] is not supported
the options [mode] is not supported
the options [tags] is not supported
the options [hedge] is not supported
the options [preference] is not supported
the options [isValid] is not supported
the options [slaveOk] is not supported
the options [equals] is not supported
the options [toJSON] is not supported
谢谢

the options [servers] is not supported
the options [caseTranslate] is not supported
the options [dbName] is not supported
the options [mode] is not supported
the options [tags] is not supported
the options [hedge] is not supported
the options [preference] is not supported
the options [isValid] is not supported
the options [slaveOk] is not supported
the options [equals] is not supported
the options [toJSON] is not supported