eg: the input is
{
"_id" : ObjectId("5e79ae1c11344b2895797042"),
"startDay" : "20200312",
"endDay" : "20200314"
}
I want to get ['20200312','20200313','20200314']. What should I do ?
eg: the input is
{
"_id" : ObjectId("5e79ae1c11344b2895797042"),
"startDay" : "20200312",
"endDay" : "20200314"
}
I want to get ['20200312','20200313','20200314']. What should I do ?
I have used $range which returns Array of numbers between range
and $range accepts only integers. So, I convert the String values of startDay and endDay to integers using $toInt
Try this query,
db.collection.aggregate([
{
"$project": {
"days": {
"$range": [
{
"$toInt": "$startDay"
},
{
"$add": [
{
"$toInt": "$endDay"
},
1
]
}
]
}
}
}
])
Query Result
[
{
"_id": ObjectId("5e79ae1c11344b2895797042"),
"days": [
20200312,
20200313,
20200314
]
}
]