2014-11-26 5 views
2

몽구스 findOne 함수 호출은 아무 것도하지 않고 다시 곤경에 처합니다. 콜백은 ... 결코 반환되지몽구스 findOne 콜백이 작동하지 않습니다.

schema.js 파일 :

var schemaSizeGroup = new Schema({ 
    sizeGroupId  : {type: Number, required: true, index: true, index: { unique: true }} 
    ,sizeGroupName  : {type: String, required: true, trim: true, index: { unique: true }} 
    ,sizeGroupValues : {type: String, required: true, trim: true } 
    ,active    : {type: Boolean, default: true } 
}, { collection: 'sizegroup' }).index({sizeGroupId : 1}); 


module.exports ={ 
    SizeGroup  : mongoose.connection.model('SizeGroup', schemaSizeGroup), 
} 

하는 index.js 파일 :

findDocumentById : function(sGroupId, callback){ 
     winston.info(" Trying to select!"); 
     model.SizeGroup.findOne({sizeGroupId : sGroupId} ,function(err, sGroup) { 

      winston.info(" Select done:"); 
      winston.info(JSON.stringify(sGroup,null,2)); 

      if(!err) { 
       if(!sGroup) { 
        callback(new Error(" No SizeObject Found for Id:" + sizeGroupId)); 
       } else { callback(null, sGroup); } 
      } 
      else { 
       callback(err); 
      } 
     }); 
    } 
} 

셀렉틴 데이터 잘 몽고 클라이언트 반환에게 정확한 데이터를 사용하여 :

db.sizegroup.find({sizeGroupId : 6}); 

mongoose.set ('debug', true) 출력을 사용할 때 다음과 같이 표시됩니다.

Mongoose: sizegroup.findOne({ sizeGroupId: 6 }) { fields: undefined } 

모든 이전 삽입 문이 성공적으로 수행되었으므로 현재 몽구스 연결이 활성화되어 있습니다.

내가 잘못 했나요?

+0

findOne은이 작업이 완료된 후 다른 프로그램에서 완료되면 작동합니다. 프로그램의 모든 삽입은 async.series와 mongoose.set ('debug', true) 출력을 사용하여 완료됩니다. 같은 프로그램 안의 데이터에 액세스 할 수없는 이유는 무엇입니까? – sueprvoice

답변

0

프로그램 흐름에서 콜백 문제였습니다. 순수한 어리 석음의 명백한 경우 ....

관련 문제