Javascript 按日期对Mongoose文档进行分组
当我从猫鼬中提取数据时,我使用Javascript 按日期对Mongoose文档进行分组,javascript,node.js,mongodb,Javascript,Node.js,Mongodb,当我从猫鼬中提取数据时,我使用 Collection.find({ isValid: true }).populate(...).then(docs => ...) 我有一个日期字段,它只是一个普通的JavaScript日期。我想按日期对文档进行分组,但我只需要两个类别 对象可以是今天(今天00:00到23:59之间)或另一天。我想我应该使用.aggregate() 我已经把这个剧本改编好了 Appointments.aggregate([ {$group: {_id: '$date
Collection.find({ isValid: true }).populate(...).then(docs => ...)
我有一个日期字段,它只是一个普通的JavaScript日期。我想按日期对文档进行分组,但我只需要两个类别
对象可以是今天(今天00:00到23:59之间)或另一天。我想我应该使用.aggregate()
我已经把这个剧本改编好了
Appointments.aggregate([
{$group: {_id: '$date', patients: {$push: '$patient'}}},
{$project: {date: '$_id', patients: 1, _id: 0}}
], ...)
所以我想我的剧本应该是这样的
Collection.aggregate([
{ group: [
{ _id: '$date is today', today: { $push: '$doc' } }
{ _id: '$date is not today', else: { $push: '$doc' } }
]},
{ $project: { ... } }
])
我想这对猫鼬来说是聪明的,但是客户端的工作效率会更高吗