我需要报告。我的数据是嵌套的。我想按日期范围过滤。日期字段字符串。我的Mongo版本3.4.2
我想在cosDate中过滤2019年的内容。也就是说,我的目标是列出1.1.2019-30.12.2019分钟。以下是我相关收藏的图片
我的示例mongo集合https://jsoneditoronline.org/?id=bcac623bb8cd401dbdb62f48bd1c3c68
将aggregate函数与filter一起使用,我们可以根据日期过滤数据。
db.demo.aggregate(
{ "$addFields": {
"costs":
{
"$filter": {
"input": "$costs",
"as": "sn",
"cond": {
"$and": [
{ "$gte": [ "$$sn.costDate", "01/01/2019" ] },
{ "$lte": [ "$$sn.costDate", "12/01/2019" ] },
]
},
}
}
}}
)