0
我有mongodb(mongoose)的nodejs应用程序。像这样:nodejs。关闭连接
var mongoose = require('mongoose');
var express = require('express');
mongoose.connect('mongodb://localhost/my_database');
.....
var DocumentSchema = new Schema({
title : String
, body : String
, date : Date
});
var Document = mongoose.model('Document', DocumentSchema);
app.get('/documents', function(req, res) {
// get all docs
Document.find({}, function(err, docs) {
docs = docs.map(function(d) {
return {title: d.title, id: d._id};
});
res.render('documents/index.jade', {documents: docs});
});
});
so所有用户使用单个MongoDB连接。我应该在每次请求后关闭连接吗?