2014-01-30 1 views
0

mongodb의 사용자 정보를 페이지 요청에서 가져 오는 고속 미들웨어 사용.표현형 미들웨어 mongodb 실행이 작동하지 않음

요청시 userInfo를 설정하십시오. 요청시 userinfo가 표시되지 않습니다. 아래 코드를 확인하고 제안 해주십시오.

는 app.js

app.use(userManager.userManager); 

userManager.js

"use strict"; 

var USERModel = require("./user_schema"); 

module.exports.userManager = function(req, res, next) { 

     var assoString = "US"; 
     var options = { 
      limit: 1 
     }; 
     USERModel.textSearch(assoString, options, function (err, output) { 

      if (err) { 
       console.error("USERModel.textSearch:" ,err); 
      } 
      else if (output && output.results && output.results.length > 0) { 

       req.userInfo = output.results[0].obj.userDetail; 

      } 
      else { 
       console.warn("Empty USERModel for ", assoString); 

      } 
    }); 
}; 

user_schema.js

"use strict"; 

var db = require('../lib/db_connect'); 
var textSearch = require("mongoose-text-search"); 

var userSchema = new db.Schema({ 
    associatedwith : String, 
    userDetail: { 
       userId  : {type: String}, 
       cId  : {type: String}, 
       device   : {type: String}, 
       contentType  : {type: String}, 
       isCompression : {type: Boolean}, 
       renderType  : {type: String} 

      } 

    } 
); 

userSchema.plugin(textSearch); 


var USERModel = module.exports = db.mongoose.model('users', userSchema); 

답변

0
당신이 필요하거나 res.send로 (HTTP 요청 회신

, res.json, res.end 및 가족) 또는 콜백을 호출하여 요청을 th로 전달합니다. 다음 미들웨어 또는 경로 처리기 :

app.use(function(req,res,next){ 
    // Rest of the logic 
    res.send(200,'Everything went OK'); // The request is replied here 
}); 

app.use(function(req,res,next){ 
    // Rest of the logic 
    next(); // To the next middleware/route logic 
}); 
관련 문제