我正在使用Node.JS(6.6.0)应用程序,该应用程序使用MongoDB(3.2.10)作为数据库和Mongoose(1.4.X)库 . 下面的代码应该在MongoDB数据库上执行查询:
const JobStat = require('../models/job_stat')
const co = require('co')
let statService = {
getRecentJobsStat () {
return co(function* () {
// Another async code
let result = yield JobStat
.$where(function () {
let condition = true
// I omit full condition since it does not matter here
return condition
})
.sort({
value: 1
})
.exec()
return result
})
}
}
module.exports = statService
不幸的是它不起作用并生成此异常:
SyntaxError: missing ; before statement @:2:12
当我在$中更改变量定义时,其中回调函数从let到var(var condition = true),此查询已成功执行 . 我使用6.6.0版本的Node.js,另一个ES6功能对我来说很好 . 所以问题是:这个错误的原因是什么?我的代码或MongoDB / Mongoose中是否存在问题?谢谢你的帮助 .
UPD: 我在mongo shell中运行了这个查询并得到了完全相同的结果: