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連接。我應該在每次請求後關閉連接嗎?