似乎当我连接到mongodb
使用connect
api
of时,我在对象mongoose
内得到了一个连接数组connection
const connection = await mongoose.connect(process.env.DATABASE_URL);
var dbClient = connection.connections[0].client;
如果我想关闭连接,我是否需要遍历每个连接connection
,或者是否有更高级别的 api 可以关闭所有连接?
您可以使用: mongoose.disconnect();
Mongoose参考:https://mongoosejs.com/docs/api/connection.html#Connection.prototype.close() 这是参考链接:如何使用mongoose关闭mongodb连接