需求很简单,把当天(国庆当天)订单所有金额合计一下,调试不出来,查阅了论坛都提到数据库聚合日期比较没法比呀:
const res = await db.collection( 'orders' ) .aggregate() .addFields({ matched: $.and([$.gt([ '$addTime' , new Date( '10/1/2019' )]), $.lt([ '$addTime' , new Date( '10/2/2019' )])]) }) .match({ sellerId: openid, status: $.neq(-1), matched: true }) .group({ _id: null , totalFinalSum: $.sum( '$finalSum' ) }) .end() |
var start = $.dateFromParts({
year: 2019,
month: 10,
day: 1,
hour: 0,
minute: 0,
second: 0,
millisecond: 0,
timezone: 'PRC'
}),
end = $.dateFromParts({
year: 2019,
month: 10,
day: 2,
hour: 0,
minute: 0,
second: 0,
millisecond: 0,
timezone: 'PRC'
})
***.addFields({
matched: $.and([$.gte(['$addTime', start]), $.lte(['$addTime', end])])
}).***