云函数后台报错日志:
2019-11-01T03:15:08.827Z gDate is: 2019-11-01T03:15:08.827Z
2019-11-01T03:15:08.827Z lDate is: 2019-12-01T03:15:08.827Z
2019-11-01T03:15:08.890Z { Error: errCode: -501007 invalid parameters | errMsg: [InvalidParameter] Check request parameter fail. Please check your request, but if the problem cannot be solved, contact us.;
at new CloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6389:28)
at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6441:16)
at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1672:23)
at Aggregate.<anonymous> (/var/user/node_modules/wx-server-sdk/index.js:1351:41)
at step (/var/user/node_modules/tslib/tslib.js:136:27)
at Object.next (/var/user/node_modules/tslib/tslib.js:117:57)
at fulfilled (/var/user/node_modules/tslib/tslib.js:107:62)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
errCode: -501007,
errMsg: '[InvalidParameter] Check request parameter fail. Please check your request, but if the problem cannot be solved, contact us.; ' }
END RequestId: cf12d219-fc55-11e9-945a-5254007aa7a1
Report RequestId: cf12d219-fc55-11e9-945a-5254007aa7a1 Duration:69ms Memory:256MB MaxMemoryUsed:36.683594MB
云函数代码为:
无效参数,字段为date类型,不能直接与new Date的对象进行比较,聚合阶段使用 $.and
var d = new Date('2019-10-01'), d2 = new Date('2019-11-01 12:00:00')
var a = $.dateFromString({
dateString: d.toJSON()
}), a2 = $.dateFromString({
dateString: d2.toJSON()
})
db.collection('table2').aggregate()
.addFields({
matched: $.and([$.gte(['$cTime', a]), $.lte(['$cTime', a2])]),
})
.match({
matched:!0
})
.project({
_id:1,
cTime:1
})
.end()