Mongoose.js creates multiple connections to MongoDB from one connect() call

前端 未结 2 1302
醉梦人生
醉梦人生 2020-12-16 13:24

I am making a single connection to MongoDB via Mongoose in Node.js Express app:

var express = require(\'express\');
var mongoose = require(\'mongoose\');
mon         


        
2条回答
  •  爱一瞬间的悲伤
    2020-12-16 13:43

    That's because Mongoose uses a pool of 5 connections (by default) that are shared throughout your application. For best performance, it's best to just leave them open.

    You can alter the default behavior via the options parameter to mongoose.connect. For example:

    mongoose.connect('localhost', 'test', { server: { poolSize: 3 }}); // Use 3 connections
    

提交回复
热议问题