问题
Using below query to get the output:
db.action.aggregate([{
$match: {
"$and": [{
"timeStamp": {
"$gte": ISODate("2020-12-13T00:00:00.000-0400"),
"$lt": ISODate("2020-12-15T23:59:59.000-0400")
}
}, {
"functionStatus": "FMO_UVERSE_DTV"
}]
}
},
{
$group: {
_id: {
Dates: {
$dateToString: {
format: "%Y-%m-%d",
date: "$timeStamp"
}
},
FS: "$functionStatus"
},
JOBCOUNT: {
$addToSet: "$jobId"
}
}
},
{
$project: {
"_id": NumberInt(0),
"Dates": "$_id.Dates",
"FS": "$_id.FS",
"Total_JOB_FMO_UVERSE_DTV": {
$size: "$JOBCOUNT"
}
}
},
{
$sort: {
Dates: 1
}
}
])
When checking with 13 to 15th dates in above query below is the output.
/* 1 */
{
"Dates" : "2020-12-13",
"FS" : "FMO_UVERSE_DTV",
"Total_JOB_FMO_UVERSE_DTV" : 14
}
/* 2 */
{
"Dates" : "2020-12-14",
"FS" : "FMO_UVERSE_DTV",
"Total_JOB_FMO_UVERSE_DTV" : 973
}
/* 3 */
{
"Dates" : "2020-12-15",
"FS" : "FMO_UVERSE_DTV",
"Total_JOB_FMO_UVERSE_DTV" : 43
}
When checking with dates: 11th to 15th below is output coming where count for 13th Dec is showing 46, what needs to implement to get correct count.
====================================================================
/* 1 */
{
"Dates" : "2020-12-11",
"FS" : "FMO_UVERSE_DTV",
"Total_JOB_FMO_UVERSE_DTV" : 1198
}
/* 2 */
{
"Dates" : "2020-12-12",
"FS" : "FMO_UVERSE_DTV",
"Total_JOB_FMO_UVERSE_DTV" : 812
}
/* 3 */
{
"Dates" : "2020-12-13",
"FS" : "FMO_UVERSE_DTV",
"Total_JOB_FMO_UVERSE_DTV" : 46
}
/* 4 */
{
"Dates" : "2020-12-14",
"FS" : "FMO_UVERSE_DTV",
"Total_JOB_FMO_UVERSE_DTV" : 973
}
/* 5 */
{
"Dates" : "2020-12-15",
"FS" : "FMO_UVERSE_DTV",
"Total_JOB_FMO_UVERSE_DTV" : 43
}
来源:https://stackoverflow.com/questions/65303137/reg-data-is-not-providing-correct-number-in-mongo-aggregate-function