When I run commands on a collection and the db is closed the error isn’t returned in the callback but the function call throws instead. In my example I’m using db.collection(‘example’).isCapped() function but this could happen with almost all methods of a collection. Based on my findings seems the problem is related to the utils.getTopology method, that function throws when topology is closed but the error of that should be returned in the callback instead of throw
/mqemitter-mongodb/node_modules/mongodb/lib/utils.js:369
throw new error_1.MongoNotConnectedError('MongoClient must be connected to perform this operation');
^
MongoNotConnectedError: MongoClient must be connected to perform this operation
at getTopology (/mqemitter-mongodb/node_modules/mongodb/lib/utils.js:369:11)
at Collection.isCapped (/mqemitter-mongodb/node_modules/mongodb/lib/collection.js:252:82)
at Immediate.waitStartup (/mqemitter-mongodb/mqemitter-mongodb.js:65:24)
at processImmediate (node:internal/timers:464:21)