2011-12-12 2 views
0

나는 mongodb (몽구스)와 nodejs 응용 프로그램을 가지고 있습니다. 이렇게 :nodejs. close connection

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}); 
    }); 
}); 

그래서 모든 사용자는 단일 MongoDB 연결을 사용합니다. 각 요청 후에 연결을 닫아야합니까?

답변

1

절대 연결을 닫고 다시 열지 말아야합니다. 프로세스가 더 많은 CPU/RAM을 소비하지 않는 한 열어 두십시오.