我在MongoDB数据库中有一个集合,其中有一些数据,并希望查询数据。基于boardId、title,其中当前日期介于开始日期和结束日期之间,并且结束日期比当前日期过期。我想拿的那些文件。
样本数据
{
"_id": {
"$oid": "6464c0c6f51f03d917106612"
},
"id": 4401800840,
"boardId": 4401799576,
"name": "Distribute Branded Swag to Site Crew(s)",
"columnValues": [
{
"id": "timeline_1",
"title": "Actual Timeline",
"value": "{\"to\":\"2023-08-07\",\"from\":\"2023-08-01\",\"changed_at\":\"2023-05-02T15:15:45.669Z\"}"
}
],
"parentId": null,
"groupName": "Construction",
},
{
"_id": {
"$oid": "6464c0c6f51f03d917106616"
},
"id": 4401800551,
"boardId": 4401799576,
"name": "2 Week Lookahead Schedule-test",
"columnValues": [
{
"id": "timeline_1",
"title": "Actual Timeline",
"value": "{\"to\":\"2023-05-06\",\"from\":\"2023-03 31\",\"changed_at\":\"2023-05-03T12:10:00.565Z\"}"
}
],
"parentId": null,
"groupName": "Construction"
},
{
"_id": {
"$oid": "6464c0c6f51f03d917106617"
},
"id": 4401800726,
"boardId": 4401799576,
"name": "2 Week Lookahead Schedule",
"columnValues": [
{
"id": "timeline_1",
"title": "Actual Timeline",
"value": "{\"to\":\"2023-06-30\",\"from\":\"2023-03-27\",\"changed_at\":\"2023-05-02T15:15:45.609Z\"}"
}
],
"parentId": null,
"groupName": "Construction",
}
我使用下面的命令来获取数据,当前日期介于从日期和到日期之间,但它没有给予我任何结果。不知道我错过了什么。请指导
const currentDate = new Date();
const currentDates = currentDate.toISOString().split('T')[0];
const queryItem = {
boardId: { $in: boardIds },
groupName: "Construction",
columnValues: {
$elemMatch: {
title: "Actual Timeline",
value: {
$elemMatch: {
from: { $lt: currentDates },
to: { $gt: currentDates }
}
}
}
}
};
const constructionItems = await Items.find(queryItem).exec();
1条答案
按热度按时间62lalag41#
您在
value
中提供的数据似乎格式不正确。数据应该是这样的:然后将
queryItem
修改为:这给出如下输出:
希望这个能帮上忙