-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.5.5
-
Component/s: None
-
Environment:mongodb@3.5.5 (npm package)
-
Empty show more show less
-
Not Needed
I'm having the following problem.
I want to reuse the MongoClient instance after manually closing the connection by connecting again and strange errors appear.
const { MongoClient } = require('./lib/node_modules/mongodb'); const main = async () => { const url = '...'; const client = new MongoClient(url, { useUnifiedTopology: true }); await client.connect(); const db = client.db('testdb'); const demo = db.collection('demo'); console.log('count', await demo.countDocuments({})); // > count 81 await client.close(); await client.connect(); // > the options [servers] is not supported // > the options [caseTranslate] is not supported // > the options [dbName] is not supported // > the options [credentials] is not supported console.log('count', await demo.countDocuments({})); // > MongoError: Topology is closed, please connect // > at processWaitQueue (node_modules/mongodb/lib/core/sdam/topology.js:998:42) // > at NativeTopology.selectServer (node_modules/mongodb/lib/core/sdam/topology.js:440:5) // > at executeWithServerSelection (node_modules/mongodb/lib/operations/execute_operation.js:137:12) // > at executeOperation (node_modules/mongodb/lib/operations/execute_operation.js:75:7) // > at Collection.countDocuments (node_modules/mongodb/lib/collection.js:1569:10) // > at main (test.js:23:37) // > at processTicksAndRejections (internal/process/task_queues.js:93:5) { // > name: 'MongoError', // > [Symbol(mongoErrorContextSymbol)]: {} // > } await client.close(); } main().catch(console.error);
I understand by the error "MongoError: Topology is closed, please connect" that this should be possible. But somehow it doesn't work.
Using mongodb@3.5.5 (npm package).