如何将MongoDB查询的结果传递给const变量,以便可以在我的应用程序中全局使用它
这是我尝试过的
let dimension;
Settings.find({_id : "5d7f77d620cf10054ded50bb"}).select('dimension').exec((err , found) =>{
if(err){
console.log(err);
}else{
dimension = found[0].dimension;
console.log(found[0].dimension); ///here actually print out my expected result....
}
});
console.log(dimension) /// Here prints undefined