0
我知道我們有很多在這裏這樣的問題,但沒有一個答案似乎對我的代碼工作,一起來看看:貓鼬findOne函數返回取消定義
establishment = mongoose.model('Establishment' , new Schema({
//_id : Schema.Types.ObjectId,
name : String,
cnpj : String,
description : String,
address : String,
products : [],
isActive : {type: Boolean, default: true}
}));
app.get('/home',(req, res)=>{
var a = establishment.findOne({_id : "57d83a867d3ba20fcb657dc7" } , (err, estab)=>{
if(err){
return err;
}
console.log("inside the function: "+estab.name);
return estab
});
console.log("outside the function: "+a.name)
})
當內給出任何輸出findOne()函數,這一切都工作得很好,但是當我返回它時,只是說它是「未定義」