<分区>
function getEmployees(jobID){
MongoClient.connect(url, function(err, db){
if(err) throw err;
var dbo = db.db("mydb");
dbo.collection("employees").find({employee:jobID}).toArray(function(err, result){
if(err) throw err;
db.close();
console.log(result) // shows the employees. cool!
// how do I return result??
})
})
}
var employees = getEmpoyees(12345); // I want the employees variable to be an array of employees
我是 node.js 和 javascript 的新手,我搞不懂。我是否需要实现回调才能按照我尝试的方式使用数据?