无法使日期范围的mongodb匹配在聚合内工作
我正在尝试使用match按日期范围进行筛选 这是我目前的设置:无法使日期范围的mongodb匹配在聚合内工作,mongodb,Mongodb,我正在尝试使用match按日期范围进行筛选 这是我目前的设置: const initReport = await Report.aggregate( [ { "$lookup": { from: Like.collection.name, localField: "l
const initReport = await Report.aggregate(
[
{
"$lookup": {
from: Like.collection.name,
localField: "like",
foreignField: "_id",
as: "like"
}
}
{
"$lookup": {
from: Player.collection.name,
localField: "player",
foreignField: "_id",
as: "player"
}
},
{
"$unwind": {
path: "$player",
preserveNullAndEmptyArrays: true
}
},
{
"$lookup": {
from: Author.collection.name,
localField: "author",
foreignField: "_id",
as: "author"
}
},
{
"$lookup": {
from: Team.collection.name,
localField: "player.team",
foreignField: "_id",
as: "player.team"
}
},
{
"$unwind": {
path: "$player.team",
preserveNullAndEmptyArrays: true
}
},
{
"$lookup": {
from: League.collection.name,
localField: "player.team.league",
foreignField: "_id",
as: "player.team.league"
}
}
{
$match: {
"createdAt": { $lte: '2020-07-23T16:37:29.710Z', $gte: '2017-07-23T16:37:29.710Z' }
}
},
{
$group : {
_id : "$_id",
comment: { "$first": "$comment" },
title: { "$first": "$title" },
summary: { "$first": "$summary" },
analysis: { "$first": "$analysis" },
source_title: { "$first": "$source_title" },
source_link: { "$first": "$source_link" },
author: { "$first": "$author" },
like: { "$first": "$like" },
player: { "$first": "$player" },
createdAt: { "$first": "$createdAt" }
}
}
]
)
这将返回一个空数组
我觉得我错过了明显的,但我不确定是什么
我甚至尝试删除聚合之外的所有其他代码,除了带有日期的日期,但仍然不起作用。在提供的代码中,
$lte
和$gte
正在计算字符串而不是日期。如果比较日期对象,则会找到匹配项
$match: {
"createdAt": { $lte: new Date('2020-07-23T16:37:29.710Z'), $gte: new Date('2017-07-23T16:37:29.710Z') }
}