我是Node.js和回送框架的新手。我要实现的目标是在环回中找到一个与过滤器规范匹配的模型实例(此处为Job Model)。
链接:https://apidocs.strongloop.com/loopback/#persistedmodel-findone
这是我的代码:
job.json文件:
"properties": {
"jobname": {
"type": "string"
},
"data": {
"type": "object"
}
}
worker.js文件
var app = require('../server');
let Job = app.models.Job;
async function jobListener() {
console.log('1');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let query = { jobname: "countProvider"}
Job.findOne({ where: query }, function(err, jobResult) {
if(err) {
console.log('Error', err);
}
// console.log(typeof jobResult);
// console.log('Test');
});
while (jobResult) {
console.log('11111');
await sleep(5000);
console.log('checking for job in mongodb with a delay of 5 seconds');
}
}
jobListener();
但是当我尝试打印typeof jobResult并执行console.log('Test');时,我得到NaN。有人可以帮我解决我错的地方。任何帮助将不胜感激。
预先感谢