在where子句中,不会接受有效的moment.js对象

我有以下的sequelize查询:

let prms = periods.map((period, index, arr) => { if (arr[index + 1]) { return sequelize.models.Result.aggregate('value', 'avg', { where: { createdAt: { $lt: arr[index + 1], $gt: period }, type: hook.params.headers.type, entityId: hook.params.headers.entity } }).catch(err => console.log('err')); } }) 

现在,where对象的createdAt属性导致了我这个问题:

错误:错误:在Object.escape(C:\ Users \ George \ Source \ Repos \ myProj \ node_modules \ sequelize \ lib \ sql-string.js:50:11)上无效值1506211200000 Object.escape(C:\ Users \乔治\来源\回购\的Myproj \ node_modules \ sequelize \ LIB \方言\摘要\查询generator.js:917:22)

现在我不知道1506211200000来自哪里, arr[index + 1]period是moment.js对象,我可以通过console.log(arr[index + 1].isValid(), period.isValid()); 这打印true true 。 如果删除createdAt限制,没有问题。

有什么想法发生在这里?

注意:我正在使用Postgres

您需要使用moment#toDate方法将moment对象转换为Date对象,以在后续查询中使用它:

 ... createdAt: { $lt: arr[index + 1].toDate(), $gt: period.toDate() },