mongoose 如何把mongdb的数据赋值给全局变量?
var filter = [];
var promise = filterModel.find().exec();
promise.then(
function(queryResult){
for(var i in queryResult){
var filterId = queryResult[i].id;
var filterName = queryResult[i].name;
filter[filterId] = filterName;
}
},
function(err){
console.log('Error');
}
);
console.log(filter);
在console中没有显示变量filter的数值,请问如何使用mongoose调取数据库数据?