【发布时间】:2019-06-14 17:25:06
【问题描述】:
如果我将 from 传递为“1970-01-01”并将 to 传递为“1970-01-05”,我如何获取预订总数? p>
Reserved 数组包含所有预订的房间,日期为 from 到 to 日期
这是我的数据:
[
{
"_id": "5c0a17013d8ca91bf4ee7885",
"name": "ABC",
"reserved": [
{
"from": "1970-01-01",
"to": "1970-01-02",
"isCompleted": false
},
{
"from": "1970-01-03",
"to": "1970-01-05",
"isCompleted": false
},
{
"from": "2017-04-18",
"to": "2017-04-23",
"isCompleted": false
},
{
"from": "2018-01-29",
"to": "2018-01-30",
"isCompleted": false
}
]
}
]
我尝试使用 find 查询获取数据(我知道这是不正确的)
db.collection.find({
reserved: {
$not: {
$elemMatch: {
from: {
$lt: "1970-01-07"
},
to: {
$gt: "1970-01-05"
},
"isCompleted": true
}
}
}
})
【问题讨论】:
-
您正在尝试的查询是什么?
-
@RaviKumarGupta 我会更新我的代码。很抱歉给您带来不便
-
@RaviKumarGupta 我已经更新了我的问题。
标签: node.js mongodb mongoose mongodb-query aggregation-framework