Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:38:59+00:00 2026-06-12T03:38:59+00:00

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

  • 0

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

var express = require('express');
var mongoose = require('mongoose');
mongoose.connect('localhost', 'test');

I then define schema, followed by models, and lastly the controller that pulls all users from the database:

app.get('/users', function (req, res) {
  return User.find(function (err, users) {
    if (!err) {
      return res.send(users);
    }
  });
});

These DB connections open during the application start and they stay open for the duration of the node.js application.

What bothers me is why do I have 5 connections open? As soon as I close the node.js app, all 5 connections are closed.
enter image description here

Related note: For a REST API server is it better to have MongoDB connection always open. Or is it better to manually open/close connections per each user request?
d

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:39:00+00:00Added an answer on June 12, 2026 at 3:39 am

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a single page application, and one approach I am considering is keeping
Is there a trick to making 9patch images with single pixel borders? I'm not
I can't seem to get this little AIR app I'm making to work right.
I am creating a mobile app that will connect to a zendamf implementation to
I have a long running PHP script. I am making the database connection at
I learnt about prepared statements when making a JDBC-enabled Java application, and my app
I am making a app in Delphi 6 + MySQL database using standard data-aware
I'm making two programs; a server application (single instance), and a client application (multiple
I'm trying to return a single row from a database: using (connection = new
I have folowing code of c# in which I am making connection with access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.