2 回复
ylong
ylong1 楼6 年前

比较Date用  db.command.aggregate.lte

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-server-api/database/aggregation/operators/lte.html

查询字段 time <= 2019-10-01的记录,time必须是数据库Date类型

const $ = db.command.aggregate

var d = new Date('2019-10-01'),

a = $.dateFromString({

    dateString: d.toJSON()

})

db.collection('xxx').aggregate()

.addFields({

    matched: $.lte(['$time', a]),

})

.match({

    matched:!0

})

.end()

fanglong
fanglong2 楼6 年前