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.
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…